Ethical Hacking

Learn to find vulnerabilities before the bad guys do! Gain real world hands on hacking experience in our state of the art hacking lab. Course designed and taught by expert instructors with years of penetration testing experience. 12 student maximum in every class. Certification attempt included in every package.
Computer Forensics Training at InfoSec Institute

Gain the in-demand skills of a certified computer examiner, learn to recover trace data left behind by fraud, theft, and cybercrime perpetrators. Discover the source of computer crime and abuse at your organization so that it never happens again. All of our class sizes are guaranteed to be 12 students or less to facilitate one-on-one interaction with one of our expert instructors.




Network Security Secure-Shell
[Top] [All Lists]

Re: sftp status error/status code

Subject: Re: sftp status error/status code
Date: Fri, 13 Apr 2007 13:07:08 -0500
In the last episode (Apr 12), alan.cline@sas.com said:
Is there a way to receive "sftp status codes" as part of the sftp
command response message on stdout, when an sftp command is issued on
stdin.

For instance: Issuing the "get" command interactively to an ftp
server, I receive the following response on stdout:

550 filename: No such file or directory.

The same command sent to an OpenSSH sftp server receives the
following response:

Couldn't stat remote file: No such file or directory. File "/local/abbb/foo" 
not found.

I need to programmatically extract the status code off the stdout
output.  However, I haven't found a way to get the "status code" in
stdout.

Does anyone know of a way to get the "sftp status codes" sent to
stdout, like ftp servers do?

The answer is that there is no FTP-like status code.  The SFTP protocol
is more like NFS, SMB or other network filesystem protocols.  You stat
a filename to see if it's a directory, if it's not, you open it and get
a filehandle back, then you read small chunks of the file in a loop
until a read returns EOF.  What's happening to you is the stat is
failing, and sftp is printing "Couldn't stat remote file: %s", where %s
is the error string passed by the server in its error packet.

http://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-9.1

If you want to transfer files from within a program, check out curl's
library API.  Versions 7.16.1 and newer support the sftp and scp
protocols.

-- 
        Dan Nelson
        dnelson@allantgroup.com

<Prev in Thread] Current Thread [Next in Thread>