title: Renci SSH.net changing remote SFTP port request C#
body: <p>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.</p>
  
  <p>I have used Renci SSH.net before for other applications similar to this with no issues at all.</p>
  
  <p>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.</p>
  
  <p>Here is my code </p>
  
  <pre><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));
  
      }
  </code></pre>
  
  <p>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.</p>
  
  <p>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</p>
  
  <p>I used WinSCP to test the connection to the remote server through the SOCKS proxy on the port 50101 and it connected through fine.</p>
  
  <p>I used wire shark to try and trap my outgoing connection request and there I can see the Port request has changed to 50297</p>
  
  <p>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</p>
  
  <p>Thanks in advance   </p>