No Connection while GetListing

Apr 22, 2013 at 3:55 PM
I'm trying to get a listing of files on ftp but I get the following message:

No connection could be made because the target machine actively refused it 192.168.199.98:53807

My Code:
            if (DirectoryExists(directory))
            {
                using (FtpClient client = Connect())
                {
                    FtpListItem[] list = client.GetListing(pathOnFtp, FtpListOption.Modify);
     }
}
Before that code runs the application connects to the ftp with that code:
                using (FtpClient client = Connect())
                {
                    log.Debug("Trying to Connect...");
                    client.Connect();
                    FtpCapability caps = client.Capabilities;
                    log.Debug("Success - ServerCapabilities: " + caps.ToString());
                    client.Disconnect();
                }
My Connect-Method:
        private FtpClient Connect()
        {
            FtpClient client = new FtpClient();
            client.Host = serverUrl;
            client.Port = 21;
            client.Credentials = new NetworkCredential(user, password);
            client.EncryptionMode = FtpEncryptionMode.None;
            client.DataConnectionType = FtpDataConnectionType.EPSV;

            return client;
        }
Why does it fail with GetListing?

Kind Regards
Steffen
Coordinator
Apr 23, 2013 at 2:36 AM
Sounds like a firewall problem. Make sure the ports the server is handing out for passive connections are accessible from the client.
Apr 23, 2013 at 8:02 AM
I can connect to it when using FTPClient.Connect(). When using another FTP-Client like SmartFtp I can connect to the ftp.
Coordinator
Apr 23, 2013 at 2:39 PM
The problem isn't with the control connection, it's with the data connection which is what file listing and transfers use. Look that debugging example to see how to get a trace of what's going on and post it back here. The trace should show the IP address and port number that the data connection is using. Might give a clue as to why it's being blocked or otherwise not making the connection.