Search code examples
c#.netftphostname

.NET Unknown Hostname exception but nslookup works


I am writing a program that downloads FTP files with FluentFTP, but I get the following exception when trying to connect:

Host desconocido
en System.Net.Dns.GetAddrInfo(String name)
en System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)
en System.Net.Dns.GetHostAddresses(String hostNameOrAddress)
en FluentFTP.FtpSocketStream.Connect(String host, Int32 port, FtpIpVersion ipVersions)
en FluentFTP.FtpClient.Connect(FtpSocketStream stream)
en FluentFTP.FtpClient.Connect()

However, when I do a ping to the same address and the same port, it works, and nsloopup can resolve the hostname. Any clue on why it doesn´t work?


Solution

  • I did the dumb mistake of instantiating FtpClient sending the port number in the host string instead of as its own parameter. Passing the port number like this worked:

    using (var client = new FtpClient(host, port, userName, password)){
        //code
    }