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..