sshnet / sshnet/SSH.NET

Renci SSH.net changing remote SFTP port request C#

Open
#471 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
4.4k
Forks
993
Avg merge
9d 21h
Merged PRs (30d)
1

Description

I am writing a small piece of code in C# (VS 2017) to upload files to a remote server using SFTP through a SOCKS Proxy.

I have used Renci SSH.net before for other applications similar to this again going through the SOCKS proxy with no issues at all.

However in this application I am having an problem where the Renci SSH.net call to the Socks proxy is for a different Port to the one I requested.

Here is my code
`private static void testSFTPConnection()
{
//get the SFTP Connection Info
ConnectionInfo connInfo = testRemoteSFTP();
try
{
//Start the SFTP Client
using (SftpClient remoteSFTPClient = new SftpClient(connInfo))
{
//Connect the remote session
remoteSFTPClient.Connect();

            //log a successful connection
           Console.WriteLine("SFTP File Upload - connection to the file destination server successful");

            //Disconnect the Destination SFTP connection
            remoteSFTPClient.Disconnect();
        }
    }
    catch(Exception ex)
    {
        Console.WriteLine("SFTP File Upload Exception: " + ex.Message);
    }
}

public static ConnectionInfo testRemoteSFTP()
{
return new ConnectionInfo(remoteHost,50101, remoteUser,ProxyTypes.Socks5, proxyURL,proxyPort, proxyUser, proxyPwd, new PasswordAuthenticationMethod(remoteUser,remotePwd));

}

`
As you can see I am setting the Connection info to call the remote host on port 50101 (as per their request) However when I run the code the SOCKS Proxy tells me I am requesting a connection to the remote server on Port 50297.

When I tried to debug the connection information in VS 2017, the connection object shows me the Port request as being 50101 but it still hits the proxy requesting port 50297

I used WinSCP to test the connection to the remote server through the SOCKS proxy on the port 50101 and it connected through fine.

I used wire shark to try and trap my outgoing connection request and there I can see the Port request has changed to 50297

I am now out of ideas as to what the cause of this could be or what fix to apply so any help in this regard would be appreciated

Thanks in advance

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided ConnectionInfo and SftpClient example with the SOCKS5 proxy, requesting remote port 50101. Compare the proxy request in Wireshark with the WinSCP connection, then identify why SSH.NET sends port 50297; done when the cause and a verified fix or limitation are established.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.