www.libssh2.org | Daily snapshots | Mailing list archive | Docs | Examples | github

Archive Index This month's Index

Subject: Re: libssh2_sftp_open() error values

Re: libssh2_sftp_open() error values

From: Alexander Lamaison <swish_at_lammy.co.uk>
Date: Fri, 24 Jul 2009 22:57:10 +0100

The usual error procedure with libssh2_sftp_* functions is to first
call libssh2_session_last_error to make sure the error wasn't
something SSH related like a broken connection. This function returns
an error message in its second parameter.

Assuming the was no SSH, this function will return
LIBSSH2_ERROR_SFTP_PROTOCOL in which case you can call
libssh2_sftp_last_error to get more detail. This returns an error
code but no error message so I have my own function,
GetSftpErrorMessage that just maps these codes to strings. Here is my
error handling function in case it helps to see code:

 * Retrieves a string description of the last error reported by libssh2.
 * In the case that the last SSH error is an SFTP error it returns the SFTP
 * error message in preference.
CString GetLastErrorMessage(const CSession& session)
        int nErr; PSTR pszErr; int cchErr;

        nErr = libssh2_session_last_error(session, &pszErr, &cchErr, false);
        if (nErr == LIBSSH2_ERROR_SFTP_PROTOCOL)
                ULONG uErr = libssh2_sftp_last_error(session);
                return GetSftpErrorMessage(uErr);
        else // A non-SFTP error occurred
                return CString(pszErr);

However, I have been having problems with libssh2_sftp_open. For
instance it returns LIBSSH2_FX_NO_SUCH_FILE when the file is locked or
already exists and I passed the CREAT flag. I assume this is
OpenSSH's fault and that libssh2 just returns whatever the server
sends it.



2009/7/24 royconejo <royconejo_at_gmail.com>:
> well, libssh2_sftp_open() returns NULL whenever it fails, but how could I
> discern if it was because of the ?
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2009-07-24

the libssh2 team