Hi everyone. I'm using the library to upload files to a remote server using the
SFTP module but sometimes I have network problems like disconnections or the
remote server closes the connection.
My problem is that the library doesn't report the error code correctly or I'm
not using it correctly.
The first thing I do is initialize the ssh & sftp sessions then I try to open a
file on the remote server using sft_open:
if (!(file = sftp_open(m_session->sftp, remotePath.c_str(), oFlags, S_IRWXU)))
throw
SysErr::CSysException(sftp_get_error(m_session->sftp),CXP_ECAT_SFTP_ERROR,ssh_get_error(m_session->ssh));
This works fine, but sometimes when the network fails or the remote server
closes the connection, I can't get the correct error code, but I can get the
error message.
For example, some errors I get are:
sftp.error ecode: 0 message: Socket error: Connection reset by peer
sftp.error ecode: 4 message: Socket error: Connection reset by peer
sftp.error ecode: 4 message: Socket error: connected
As you can see, the ssh_get_error(m_session->ssh) function works fine and
reports the correct error message, but I don't know if it's correct to use
sftp_get_error(m_session->sftp) to get the error code or maybe I should always
use the ssh_get_error_code function to get the error code.
As I have seen, 0 is no error (SSH_FX_OK: no error) and 4 is general failure
(SSH_FX_FAILURE: generic failure), I would expect to receive an error like:
SSH_FX_NO_CONNECTION: no connection has been set up
SSH_FX_CONNECTION_LOST: there was a connection, but we lost it
I'm using multithreading on linux with the C++ thread library and each thread
has its own instance of the SFTP class I've created. This actually works fine
but after some time of use I have the network issues mentioned and I am unable
to detect disconnections and retry a new connection.
So my question is what is the correct way to know when a disconnection occurs
using an error code and not analyzing the error message to find the
disconnection or reset by the peer?
Best regards,
John.