SFTP module not report errors codes correctly
When use the SFTP module, some errors codes are not reported correctly with SFTP session and only are notified with the SSH session string or by the SSH error code.
As can I see in the documentation, the function ssh_get_error return the error string when an error happens and the ssh_get_error_code the SSH session error code. This works fine but when some functions from SFTP module and according to documentation the error code reported by sftp_get_error is wrong.
The documentation of the SFTP module says:
In case of a problem, the function sftp_get_error() returns a SFTP-specific error number, in addition to the regular SSH error number returned by ssh_get_error_number().
Possible errors are:
SSH_FX_OK: no error
SSH_FX_EOF: end-of-file encountered
SSH_FX_NO_SUCH_FILE: file does not exist
SSH_FX_PERMISSION_DENIED: permission denied
SSH_FX_FAILURE: generic failure
SSH_FX_BAD_MESSAGE: garbage received from server
SSH_FX_NO_CONNECTION: no connection has been set up
SSH_FX_CONNECTION_LOST: there was a connection, but we lost it
SSH_FX_OP_UNSUPPORTED: operation not supported by libssh yet
SSH_FX_INVALID_HANDLE: invalid file handle
SSH_FX_NO_SUCH_PATH: no such file or directory path exists
SSH_FX_FILE_ALREADY_EXISTS: an attempt to create an already existing file or directory has been made
SSH_FX_WRITE_PROTECT: write-protected filesystem
SSH_FX_NO_MEDIA: no media was in remote drive
Errors when connection lost or has a remote server disconnection never are reported among others.
The function ssh_get_error_code reports always SSH_FATAL and ssh_get_error reports the correctly string error like:
- Socket error: disconnected
- Socket error: Connection reset by peer
but when use sftp_get_error the error returned not match with the correct error in the list of errors returned by the server.
sftp_get_error returns sometimes: the code 0 others code 4 what has nothing to do with real error. Why return 0 (SSH_FX_OK) if We have a disconnection?
I see that some functions in sftp.c not set never the SFTP session error code because never call sftp_set_error. For example:
See the function sftp_read line 1175 if the creation of the buffer fails, the SSH session error code is set but not the SFTP session error I would expect that the error code was also established in the SFTP session as is done in the same function mentioned in line 1191.
The same issue happens in fucntion sftp_open line 1021 and in the same way it happens in other places within the SFTP.C file The ssh_socket_exception_callback inside session.c has the same problem. Only set the SSH session error code but not set the SFTP session error code.
If not, what is the sense of showing a list of error codes in the SFTP module documentation if these errors will not always be reported?