SFTP Get command fails in Shell Script and works fine Manually

I'm trying to get a file using SFTP command in the shell script and it fails with "Cannot download non-regular file:". Below is the piece of code I have written.

sftp -v -F /usr/home/.ssh/sftp.config <user>@<servername> <<EOF2
cd <targetdirectory>
mget $File
bye
EOF2

Also when I try to list the files in the shell script, it gives "Couldn't get handle: Failure" error.

However, If I do the same operation manually(SFTP to get the file), I'm able to get the file successfully without any errors.

Very much confused as why the SFTP command in shell script is not allowing to download the file whereas the same set of commands when manually run works.

Any inputs is greatly appreciated. Thank you so much!!

Thanks,
Vijay
Vijay MalleshAsked:
Who is Participating?
 
dfkeConnect With a Mentor Commented:
Hi,

Unfortunately you can't do a recursive get with sftp. You should use scp instead.

scp -r user@host:/your/path/ .

Open in new window

Be sure to always use the absolute path and don't forget the '.' at the end, it is the destination directory.

Cheers
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.