Reputation: 262
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.
Upvotes: 7
Views: 19721
Reputation: 307
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
Upvotes: 3
Reputation: 192
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" />
Upvotes: 0
Reputation: 2472
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();
Upvotes: 1
Reputation: 21
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/
Upvotes: 2
Reputation: 262
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.
Upvotes: 4