SFTP connectivity DNS issue - System.Net.Sockets.SocketException: The requested name is valid, but no data of the requested type was found

Piotroslav picture Piotroslav · Dec 18, 2012 · Viewed 14.1k times · Source

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.

Answer

Piotroslav picture Piotroslav · Dec 19, 2012

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.