Reputation: 3379
I am newbie to C# and I am trying to accessing the SFTP using C# (Getting some code from internet). I tried this by writing below code. But I am getting exception as:
IPHostEntry hostInfo = Dns.GetHostByName(@"sftp://........");
// Get the IP address list that resolves to the host names contained in the
// Alias property.
IPAddress[] address = hostInfo.AddressList;
// Get the alias names of the addresses in the IP address list.
"SocketException was caught: The requested name is valid, but no data of the requested type was found"
I found a lot about this but failed to understand. Also I tried to connect the SFTP using Tamir.SharpSSH library but getting the same exceptions.
Please suggest some solution over it. I need this in my project.
Thanks
Upvotes: 2
Views: 5263
Reputation: 45761
I suspect you need to change:
IPHostEntry hostInfo = Dns.GetHostByName(@"sftp://server.address.com");
to:
IPHostEntry hostInfo = Dns.GetHostByName(@"server.address.com");
DNS doesn't know, nor care about the protocol (sftp://
) that you're using to access the server, it only cares about the servers name.
NOTE: Microsoft considers the Dns.GetHostByName
method to be obsolete and recommends that instead you use the Dns.GetHostEntry
method instead.
Upvotes: 5