Bhavesh Shah
Bhavesh Shah

Reputation: 3379

Exception while acessing SFTP site: The requested name is valid, but no data of the requested type was found

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

Answers (1)

Rob
Rob

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

Related Questions