Naresh
Naresh

Reputation: 657

Issue with running commands from shell script

I'm trying to copy files from a remote windows server to Unix server. I was successfully able to copy files from windows server using command prompt but when I run these commands from a script it's not working as expected.

commands used:

sftp user@remoteserver.com

lcd local_dir

cd remote dir

get file_name

exit

When I run these commands from a script the script is stopping after it connects to the remote server.

Can anybody tell me how to fix this issue.

Upvotes: 0

Views: 302

Answers (1)

Ingo Leonhardt
Ingo Leonhardt

Reputation: 9904

The commands lcd to exit are sftp commands, so you cannont just write them into a script line by line but have to redirect them as sftps stdin:

 # all lines till "EOF" will be redirected to sftp
 sftp user@remoteserver.com <<- EOF
 lcd local_dir
 cd remote dir
 get file_name
 exit
 EOF

 # here you are in your shell script again, eg:
 SFTPRES=$?

Upvotes: 1

Related Questions