Overview description: When downloading files from a remote server that are: Non-readable (permission denied) Non-existing (no files on remote system) ... sftp client exit-code is 0 when running the following in a script: #!/bin/sh /usr/local/bin/sftp -v -oBatchMode=yes user@host < answerfile.txt 2> debug.log echo $? 0 Answerfile: cd /var/log/testlog/test_log get /var/log/testlog/test_log/test_log_2003-04-08.log Debug-log produced from running above: ...snip... debug1: read PEM private key done: type RSA debug1: Authentication succeeded (publickey). debug1: fd 4 setting O_NONBLOCK ...snip... Couldn't stat remote file: No such file or directory File "/var/log/testlog/test_log/test_log_2003-04-08.lo" not found. debug1: channel 0: read<=0 rfd 4 len 0 debug1: channel 0: read failed ...snip... debug1: Transferred: stdin 0, stdout 0, stderr 0 bytes in 0.1 seconds debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0 debug1: Exit status 0 ...eof... And on permission denied: ...snip... debug1: Sending subsystem: sftp debug1: channel 0: request subsystem debug1: channel 0: open confirm rwindow 0 rmax 32768 Couldn't get handle: Permission denied debug1: channel 0: read<=0 rfd 4 len 0 ...snip... debug1: Transferred: stdin 0, stdout 0, stderr 0 bytes in 0.1 seconds debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0 debug1: Exit status 0 ...eof... Excpected results: Shouldn't above return exit status of >0 on these errors ? Build date and platform: OpenSSH 3.6.1.p1, Solaris 9 sparc sun4u / GCC 3.1 Also, have you considered implementing better logging of transfers?, ex standard ftp "226 Transfer complete" to stdout, instead of having to run client in debug-mode, and perhaps a configfile to specify logpath and level. I read in changelog about improved logging for sftp but can't see that the man- pages are updated. What will -DTRACE=log accomplish exactly? Thanks.
/usr/local/bin/sftp -v -oBatchMode=yes user@host -b answerfile.txt 2> debug.log use -b batch option. That is why it was created. It allows you to break when a command fails.
RTFM (sftp manpage in this case): -b batchfile Batch mode reads a series of commands from an input batchfile instead of stdin. Since it lacks user interaction it should be used in conjunction with non-interactive authentication. sftp will abort if any of the following commands fail: get, put, rename, ln, rm, mkdir, chdir, ls, lchdir, chmod, chown, chgrp, lpwd and lmkdir. Termination on error can be suppressed on a command by command basis by prefixing the command with a â-â character (For example, -rm /tmp/blah* ). And yes, -DTRACE=log in sftp-server will give you more logging.
Mass change of RESOLVED bugs to CLOSED