Problem: sftpclient-connect: An existing connection was forcibly closed by the remote host

Nov 7, 2013 at 2:09 PM
I have the following problem:

When I connect to an SFTP-Server wirh User-Password-Login, I get the following exception:

bei System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
bei Renci.SshNet.Session.SocketRead(Int32 length, Byte[]& buffer)
bei Renci.SshNet.Session.SocketReadByte()
bei Renci.SshNet.Session.ConnectSocks4()
bei Renci.SshNet.Session.Connect()
bei Renci.SshNet.BaseClient.Connect()

The error code in System.Net.Sockets.Socket.Receive results in:
10054 ConnectionReset

Here my source code:

List<AuthenticationMethod> methods = new List<AuthenticationMethod>();
            methods.Add(new PasswordAuthenticationMethod(user,pwd));

            methods.Add(new NoneAuthenticationMethod(user));

            methods.Add(new KeyboardInteractiveAuthenticationMethod(user));
            pType = ProxyTypes.Socks4;
            connectionInfo = new ConnectionInfo(host, hstPort, user, pType, proxy, prPort,      proxyUser, proxyPwd,methods.ToArray());
            Console.WriteLine("Creating client and connecting to server...");

            using (client = new SftpClient(connectionInfo))
                client.HostKeyReceived += delegate(object sender, HostKeyEventArgs e)
                        if (e.FingerPrint.SequenceEqual(new byte[] { 0x00, 0x01, 0x02, 0x03 }))
                            e.CanTrust = true;
                            e.CanTrust = false;

                //Connect to Remoteserver 
                client.ConnectionInfo.Timeout = TimeSpan.FromSeconds(30);

                Console.WriteLine("Connected to {0}", host);

                Console.WriteLine("Changed directory to {0}", targetDir);

                var listDirectory = client.ListDirectory(targetDir);
                Console.WriteLine("Listing directory:");
                foreach (var fi in listDirectory)
                    Console.WriteLine(" - " + fi.Name);

        catch (Exception ex)

            Console.WriteLine("ERROR: " + ex.Message);


Has anybody got an idea, what can be done as workaround?
Hint: A winscp connection from the same pc is successfull!