Automated SFTP script

Hi All,

I am writing an automated SFTP script to xfer files. I am able to do sftp in batch mode and it is working absolutely fine.
The problem is that on redirecting the output of SFTP session to some file, it is not writing about the status of SFTP operation. All i can see in output file is :

sftp> put file2.dst2
Uploading file2.dst2 to /data05/FTP_test/dst2/file2.dst2

Whereas in interactive mode the output is :-

sftp> put file2.dst2
Uploading file2.dst2 to /data05/FTP_test/dst2/file2.dst2 file2.dst2 100% 4096 4.0KB/s 00:00

I need to know the status of the SFTP operation so as to rename the files successfully xferred...

Am i missing anything here ?? Please help..

When running in batch mode, I don't think you have a way to catch the exit code of each operation. Instead, you can redirect everything to a log file and later grep for certain patterns like "fatal, error, couldn't" etc.

I am doing exactly that... but the log file is not writing anything after

Uploading file2.dst2 to /data05/FTP_test/dst2/file2.dst2

Is is normal sftp behaviour or am i missing something ??

That's normal, I'm usually using "nohup" in front of every ssh transfer, the STDOUT by default gets redirected to file called "nohup.out" and then I look at this file, but I'm not sure if this is going to work in batch mode.

you might consider using the FTCL scripting language .. supports FTP/S and SFTP and allows you to send debug information to a file.

Secure FTP Factory - Java SFTP, Java Secure FTP, Java FTPS, Java FTP, FTP SSL, FTP SSH

I would say if you are scripting SFTP sessions, you should not use SFTP as your client program, but a generic FTP program called LFTP (LFTP - sophisticated file transfer program) using an SSH/SFTP protocol. Covers all sorts of FTP-ish protocols and has great shell scripting support

hi aggar_y
i am trying to implement the SFTP script in solaris. could you please send me the snippet of the code which is working for you?