Re: sftp status error/status code



In the last episode (Apr 12), alan.cline@xxxxxxx 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@xxxxxxxxxxxxxxx



Relevant Pages

  • Re: NET:TELNET data output
    ... bigdogdan2@gmail.com writes: ... > instead of after the command is finished? ... You can send the command and read its response a block at a ... the remote host) go to stdout: ...
    (comp.lang.perl.misc)
  • Re: Problem with WSH Shell Exec StdOut
    ... catch its StdOut stream in real time. ... NeroCmd.exe is a command line utility included ... Here is the script I'm currently using: ...
    (microsoft.public.scripting.vbscript)
  • Re: Problem with WSH Shell Exec StdOut
    ... catch its StdOut stream in real time. ... then almost immediately I get a command window displaying the following: ... You have to abort the script by ending the ...
    (microsoft.public.scripting.vbscript)
  • Re: Can you duplicate Standard Output WITHOUT tee command?
    ... run where he wanted to catch stdout. ... Yes, this is a difficult command pipe, especially as written it uses ... The last file descriptor operations restore the normal meaning of stdin ...
    (comp.unix.shell)
  • Re: Problem with WSH Shell Exec StdOut
    ... catch its StdOut stream in real time. ... NeroCmd.exe is a command line utility included with or ... Here is the script I'm currently using: ...
    (microsoft.public.scripting.vbscript)

Quantcast