简体   繁体   中英

C# Error in SFTP connection. Exception: System.Net.Sockets.SocketException (11001): No such host is known

I have written a SFTP connection, which is connecting to a secure domain host (MBox location) in .NET Core:

IPHostEntry ip = Dns.GetHostEntry(Host);

using (SftpClient client = new SftpClient(ip.ToString(), Port, User, Password))
{
    //connect to client
    client.Connect();
    var files = client.ListDirectory(PathToRead).ToList();
    ......
    //wait for downloads to finish
    await Task.WhenAll(tasks);

    // disconnect the client by closing connection
    client.Disconnect();
}

which is hosted in Azure App service with subscription and Azure AD configured as per my client's domain. When I am running the code I am seeing the following error:

Error in FTP connection. Exception: System.Net.Sockets.SocketException (11001): No such host is known

Can you please help.

ip.ToString() returns the name of the type, System.Net.IPHostEntry . Your SftpClient is then trying to look up System.Net.IPHostEntry in DNS and not finding anything, thus the exception.

I'm not familiar with the constructors provided by SftpClient , but presumably you need to do something like:

using (SftpClient client = new SftpClient(ip.AddressList, Port, User, Password))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM