Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

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

$
0
0
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;
                        }
                        else
                        {
                            e.CanTrust = false;
                        }
                    };

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


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

                client.ChangeDirectory(targetDir);
                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);

                }
            }//using
        }
        catch (Exception ex)
        {

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

            throw;
        }
...

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

Viewing all articles
Browse latest Browse all 1729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>