cancel
Showing results for 
Search instead for 
Did you mean: 

sftp script

 
SOLVED
Go to solution

sftp script

Hi,
I want to script sftp between two HP-UX servers. The sftp works fine when I issue commands at command line:
sftp USER@HOST
sftp> cd /tmp
sftp> lcd /tmp
sftp> put testfile
sftp> bye

But when I try to script using:

sftp -b /dev/null HOST << EOF
cd /tmp
lcd /tmp
put testfile
quit
EOF

Then there is no error on the terminal or in the remote hosts syslog.log but the file is not transferred.
Any ideas what's wrong with my script? Also, should I rather be using scp or sftp? The existing mechanism on the legacy system is ftp.

Kind Regards
Graham
4 REPLIES
Matt Palmer_2
Respected Contributor
Solution

Re: sftp script

scp is easier IMO.

eg: scp /tmp/testfile user@host:/tmp

regards

Matt
Stephan.
Honored Contributor

Re: sftp script

Hi Graham,
i would try to find the problem by using

sftp -b USER@HOST -B SCRIPT

SCRIPT contains:
cd /tmp
lcd /tmp
put testfile
quit

Termination on error can be suppressed on a command by command basis by prefixing the command with a "-" character, so change the command line by line and see where the error happens.

f.e.
SCRIPT contains:
-cd /tmp
-lcd /tmp
put testfile
quit
James R. Ferguson
Acclaimed Contributor

Re: sftp script

Hi Graham:

#!/usr/bin/sh
sftp MYHOST << EOF
cd /tmp
lcd /tmp
put testfile
quit
EOF

Regards!

...JRF...
Ganesan R
Honored Contributor

Re: sftp script

Hi Graham,

I am not sure why you have used "-b /dev/null" option. Man page says,

"-b batchfile
Batch mode reads a series of commands from an input batchfile instead of stdin."

But it should work, if your script looks like this,

sftp username@0.0.0.0 <cd /path
lcd /path
put filename
EOF
Best wishes,

Ganesh.