SftpClient disconnect issue

Aug 13, 2012 at 8:40 PM
Edited Aug 13, 2012 at 11:07 PM

It seems everytime I disconnect my SftpClient and then create a brand new SftpClient and try to connect to it I receive the following error:

"System.Net.Sockets.SocketException (0x80004005): The system detected an invalid pointer address in attempting to use a pointer argument in a call"

In the log it appears that I'm not successfully receiving the "Disconnect Message" from the server like I believe i'm supposed to. 

My code is as follows:

 

using (SftpClient sftpConnection = new Renci.SshNet.SftpClient(ftpAddress, 22, ftpUsername, ftpPassword))
{
     sftpConnection.Connect();
     sftpConnection.Disconnect();

     sftpConnection.Connect();
     sftpConnection.Disconnect();
}

Edit: Something I noticed to go along with this. My work pc is inside a proxy, however the FTP address i'm connecting to is local inside the proxy domain. When I came home and tried it, it works just the way it should. So I'm guessing that has something to do with it.

Aug 14, 2012 at 5:43 PM

Update: I believe I've narrowed the problem I'm having down to a combination of being inside an http proxy (although the server is inside the proxy) and running in a background worker thread.

Aug 14, 2012 at 8:48 PM

I've messed around with this endlessly today and in the end I hacked a work around:

 

            ConnectionInfo connectionInfo = new PasswordConnectionInfo(ftpAddress, ftpPort, ftpUsername, ftpPassword, ProxyTypes.None, string.Empty, 0, string.Empty);

            using (Renci.SshNet.SftpClient sftpConnection = new Renci.SshNet.SftpClient(connectionInfo))
            {
                Dispatcher.Invoke(new Action(() => { sftpConnection.Connect(); }), null); // Instead of sftpConnection.Connect();
                Dispatcher.Invoke(new Action(() => { sftpConnection.Disconnect(); }), null); // Insert of sftpConnection.Disconnect();
            }

            using (Renci.SshNet.SftpClient sftpConnection = new Renci.SshNet.SftpClient(connectionInfo))
            {
                Dispatcher.Invoke(new Action(() => { sftpConnection.Connect(); }), null);
                Dispatcher.Invoke(new Action(() => { sftpConnection.Disconnect(); }), null);
            }

I'm completely aware that I shouldn't have to do this, but this is the only way it works and I don't have the time to dive into ground that I'm completely unfamiliar with.