7

I am trying to connect to ftp via SharpSSH as below:

Sftp Connection = new Sftp(ftpAddress, FTPLogin, FTPPasword);
Connection.Connect();

Which results in JSchException:

System.Net.Sockets.SocketException: The requested name is valid, but no data of the requested type was found
at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)
at System.Net.Dns.GetHostByName(String hostName)
at Tamir.SharpSsh.java.net.Socket..ctor(String host, Int32 port)
at Tamir.SharpSsh.jsch.Util.createSocket(String host, Int32 port, Int32 timeout)

After some search I tried this code:

IPHostEntry ip = Dns.GetHostEntry(ftpAddress);

And I got SocketException: {No such host is known}

Now some background - I am able to connect with Filezilla to ftpAdress with via hostname and IP address (both external and internal). When I >ping ftp.mydomain.com
I get >10.5.165.15
But on >ping -a 10.5.165.15
I get >ftpnew.mydomain.com

If I am right, I am being rejected because of DNS <> revDNS problem.

My question is - what can I do to actually have my sftp connection work.

Piotroslav
  • 252
  • 1
  • 4
  • 14

5 Answers5

4

Solution was found by checking every possibility and this is how I menaged to establish connection: First my ftpAddress was set to extrernal/internal IP.

IPHostEntry ip = Dns.GetHostByName(ftpAddress);
Sftp Connection = new Sftp(ip.ToString(),FTPLogin,FTPPassword);
Connection.Connect()

It seems my error was not about DNS<>revDNS but rather due to extra '\' signs in host adress I was trying to call.

Piotroslav
  • 252
  • 1
  • 4
  • 14
3

Enter only the ip address for the host. For example

Wrong : "sftp//10.11.12.13" this will result in error Correct: "10.11.12.13" this is ok

snnpro
  • 193
  • 2
2

I was facing the same problem now i found the solution for this. Use following type ftpAddress(URL): sftp.abcdefg.com with 22 port no. and rest will be same. Do not use any kind of forward slash "/" and backslash "\" at the end or starting of URL. I was facing the same problem with this URL = sftp.abcdefg.com/

vefthym
  • 7,422
  • 6
  • 32
  • 58
1

mine works when I re-arranged the name and address a little bit. Get rid of sftp:// in the beginning of the host name. and , add back 22 port in the parameters.

 using X = Renci.SshNet;

     ConnectionInfo = new X.ConnectionInfo(_host, 22, _usr, 
        new X.AuthenticationMethod[] {
        new X.PasswordAuthenticationMethod (_usr, _pwd)
     }); //_host = yourfavoritesite.whatever.com -- take out sftp://

     SftpClient = new X.SftpClient(ConnectionInfo);
     SftpClient.Connect();
Jenna Leaf
  • 2,255
  • 21
  • 29
0

Another source of this error is if there is a white-space at the beginning of the server name e.g.:

    <add key="SftpHost" value=" sftp.whatever.com" />
outofcoolnames
  • 182
  • 2
  • 5