I got some code sending files to a sftp.
Occationally I get the error "the server has closed the connection.".
The strange thing is that I get an "already connected" error when reconnecting (Sftp.Connect
). The log looks like this:
VERBOSE Sftp(1)[7] SSH: Sending packet SSH_MSG_CHANNEL_DATA (89 bytes).
INFO Sftp(1)[7] Command: SSH_FXP_OPEN (142, 'xxx.xml', 26)
VERBOSE Sftp(1)[7] SSH: Received packet SSH_MSG_CHANNEL_CLOSE (5 bytes).
VERBOSE Sftp(1)[7] SSH: Sending packet SSH_MSG_CHANNEL_CLOSE (5 bytes).
ERROR Sftp(1)[7] Info: Rebex.Net.SftpException: The server has closed the connection.
VERBOSE Sftp(1)[7] SSH: Sending packet SSH_MSG_DISCONNECT (27 bytes).
ERROR Sftp(1)[7] Info: System.InvalidOperationException: Already connected to the server.
The code looks something like this:
try {
using (var uploadStream = _sftp.GetUploadStream(fileName)) {
...
return;
}
}
catch (SftpException ex) {
if (ex.Code != SftpErrorCode.UnknownError)
throw;
if (ex.Status != SftpExceptionStatus.ConnectionClosed)
throw;
_sftp.Connect(url);
_sftp.Login(user, password);
goto retry;
}