0

I am downloading all files in a directory via SFTP using below syntax:

sshpass -p 'mypass' sftp name@$IP:/var/log/* 

With above one-liner, I'm able to download all files from /var/log

But I want the $IP to be appended with each file name being downloaded

I am able to do it for a per file bases i.e. if I download single file, I can appended the IP before the file name. But as you would have guessed, in some cases I don't know how many files are there and I think it would be an overhead as well if I keep doing SFTP to download one file at a time.

I tried below to download one file with IP appended before the file name:

sshpass -p 'mypass' sftp name@$IP < <(echo "get /var/log/file1.log ${IP}.file1.log" ) 

Also I checked in SFTP shell itself, I am not able to find any sort of loop or parameter expansion. So apparently if there's a way, it has to be like the ones I am trying.

Note: SFTP is the only option, and not scp/rsync etc..

Ibraheem
  • 23
  • 1
  • 6
  • Why do you believe is SFTP the only option? – Michael Hampton Jun 27 '20 at 15:46
  • I know it is, it is a Telecom equipment with very limited functionality – Ibraheem Jun 27 '20 at 21:05
  • You mean the client is limited, or the server is limited? – Michael Hampton Jun 27 '20 at 21:46
  • The server, From where I want to get the files, – Ibraheem Jun 27 '20 at 22:07
  • And these are hundreds of such nodes, from where I want to get the files, these are syslog files, and I want to append the IP (and date) information with each file. I thought of another solution, to create hundreds of directories, unique for an IP, and then download the files from a given IP in it's own directory, but first I want to learn if there is such possibility as I asked in the question or not? – Ibraheem Jun 27 '20 at 22:09
  • You can and probably should still use the `scp` command. It's much more conducive to automation. And it uses the server's sftp subsystem. – Michael Hampton Jun 27 '20 at 22:31
  • I tried scp and it returned the error: `exec request failed on channel 0`. How do you suggest I should do it and append a variable name before the file name. – Ibraheem Jun 28 '20 at 09:31

0 Answers0