Is there a way to print filename with path from SFTP in Unix server?

2

I am trying to print file names along with path from SFTP server to other location. I am able to get file names but not path. Below is the code that I have used:

echo "ls *.gpg" | sftp xfer@nsb.abc.com:/SXMPMX/INBOUND/FORDCOI_CONT_RESP > $Path/sample.txt

Please let me know is there any way to solve my problem.

Midhun

Posted 2018-02-08T08:19:59.767

Reputation: 21

Answers

0

In general many things can get easier with FUSE.

Use FUSE and deal with paths locally, using local tools like find. This is very similar to my another answer about FTP, you just need sshfs instead of curlftpfs.

Having a SFTP share mounted under e.g. /some/mountpoint/, cd to where you want and use

realpath --relative-to /some/mountpoint/ *.gpg

Example:

$ sshfs xfer@nsb.abc.com:/ /some/mountpoint/
$ cd /some/mountpoint/SXMPMX/INBOUND/FORDCOI_CONT_RESP
$ realpath --relative-to /some/mountpoint/ foo.gpg   # assuming the file exists
SXMPMX/INBOUND/FORDCOI_CONT_RESP/foo.gpg

Kamil Maciorowski

Posted 2018-02-08T08:19:59.767

Reputation: 38 429

In local i can able to print file name with path by using readlink -f *.txt command. i wanted to print the file name and path from SFTP. – Midhun – 2018-02-08T08:49:31.777