In the last episode (Apr 12), [EMAIL PROTECTED] 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 [EMAIL PROTECTED]
