SFTP not working in cron

Hi,

I have a simple script that is trying to put a file that resides on a local machine to a remote machine. It runs fine manually but does not complete when scheduling to run in cron. Here is what the script looks like. Any idea what I am doing wrong here?

#!/bin/ksh
cd /path
sftp remoteuser@remotehost:/path <<EOF
mput Test.txt
bye

#!/bin/ksh
cd /path
sftp remoteuser@remotehost:/path <<EOF
mput Test.txt
bye
EOF

I'm assuming that leaving off EOF was a typo.

sftp used that way requires that authentication keys be set up on the remote host.
What local user is authenticated to remoteuser on the remotehost? And is the script running as that user, ie., do you su to the required local user?

Jim,

Thanks for your reply. We have generated keys on both the source and destination machines authenticating the user. We are running the script from this user. If I type it manually from a command prompt "TestSFTP.sh", it works fine. However when I put it in cron it doesn't.

As a further test, I put in an additional line in cron to send me an email.

#!/bin/ksh
mailx -s "Test" myemail@myemail.com < /path/TestSFTPcron.txt
cd /localpath
sftp remotename@remotehost:/remotepath <<EOF
mput Test.txt
bye
EOF

When I do this, it also works completely fine when I run it manually. However, in cron I so receive the email but the file is not put on the remote machine.

It looks like the script is partially working...

okay - you need to have the script run by cron as that user - use the man page for su to show you how to do that.

Hi,

Have you go this problem resolved ? even I am facing a similar problem. My script works fine when run manually from command prompt, but it is failing when put in to the crontab. How did you fix this problem?

Thanks.
Abhi.