Bug 542 - OpenSSH 3.6.1p1 - sftp exit codes and improved logging for scripting
Summary: OpenSSH 3.6.1p1 - sftp exit codes and improved logging for scripting
Status: CLOSED WORKSFORME
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: sftp (show other bugs)
Version: -current
Hardware: SPARC Solaris
: P2 normal
Assignee: OpenSSH Bugzilla mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-04-10 02:54 AEST by Magnus Forsberg
Modified: 2004-04-14 12:24 AEST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Magnus Forsberg 2003-04-10 02:54:51 AEST
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.
Comment 1 Ben Lindstrom 2003-04-10 03:07:27 AEST
/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.   
Comment 2 Damien Miller 2003-04-10 10:34:29 AEST
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.
Comment 3 Damien Miller 2004-04-14 12:24:19 AEST
Mass change of RESOLVED bugs to CLOSED