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...
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.
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.
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