No Connection while GetListing

Apr 22, 2013 at 2: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

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...");
                    FtpCapability caps = client.Capabilities;
                    log.Debug("Success - ServerCapabilities: " + caps.ToString());
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
Apr 23, 2013 at 1: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 7:02 AM
I can connect to it when using FTPClient.Connect(). When using another FTP-Client like SmartFtp I can connect to the ftp.
Apr 23, 2013 at 1: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.