GetListing hangs my application

Jun 18, 2012 at 10:22 PM

I am just experimenting with this library, but I can't get GetListing or GetRawListing to not hang.  I am able to call GetLastWriteTime perfectly fine.  

My objective is to find the most recently changed file that meets a wildcard pattern, specifically current date with a variable hour (06172012*.csv).  I want to only download the file that matches that pattern and was last written.

Coordinator
Jun 18, 2012 at 10:26 PM

Are you using active or passive mode for the data channel? Sounds like a typical firewall/router issue, the client can't connect the data channel properly. Please include debug output if you can. You can log it to the console or to a file a file.

FtpClient client = new FtpClient();
client.FtpLogStream = Console.OpenStandardOutput();
client.FtpLogFlushOnWrite = true;

Thanks,

J.P.

Jun 19, 2012 at 2:18 PM
Edited Jun 19, 2012 at 2:29 PM

using
(var cl = new FtpClient("login", "password", "site", 21)) { cl.SetWorkingDirectory("/"); var test = cl.GetLastWriteTime("/outgoing/file.csv"); var test2 = cl.GetListing("/");
Here is my code. FtpLogStream and FtpLogFlush do not appear to be properties on the FtpClient Object. My application just freezes up when I call the last line.
EDIT sorry for terrible format: Maybe someone can help me, for some reason the code snippet won't stop.  I had to go in and edit the html source to fix it.
Coordinator
Jun 19, 2012 at 2:29 PM

What about FtpClient.FtpLogStream and FtpClient.FtpLogFlushOnWrite? They used to be static properties however that was changed. It's possible you're using an older version. I'm not sure if the binary download has the static or non static properties. Wouldn't hurt to download the latest revision.

Jun 19, 2012 at 2:42 PM
Edited Jun 19, 2012 at 2:42 PM

I just downloaded this yesterday, and I used the 2012.03.19 link.  It is the current version.  Oh, I see them when using static, your code sample above is not a static example and can't be used from a non static reference.

Here is the output:

 

> 250 Directory successfully changed.
 211-Features:
>  EPRT
>  EPSV
>  MDTM
>  PASV
>  REST STREAM
>  SIZE
>  TVFS
> 211 End
< MDTM /outgoing/file.csv
> 213 20090105112934
< TYPE A
> 200 Switching to ASCII mode.
< EPSV
> 229 Entering Extended Passive Mode (|||9436|)
< LIST /
Coordinator
Jun 19, 2012 at 2:59 PM

It looks like a firewall is blocking the data channel connection. Your firewall configuration needs to allow incoming connections on the passive ports your FTP server is configured to use. By default, passive ports are chosen at random by the server however most server software allows you to configure a specific range or ports. Alternatively you can try a different data channel type, cl.DataChannelType = FtpDataChannelType.Passive; for example. The default is ExtendPassive (EPSV), you can try ExtendedActive or Active mode transfers as well.

Jun 19, 2012 at 4:13 PM

Yeah the firewall didn't make sense because I could connect through FileZilla and using FtpWebRequest, with the same site.  It did work using the cl.DataChannelType = FtpDataChannelType.Passive.  Thanks I wasn't sure how to set it to passive.

Coordinator
Jun 19, 2012 at 4:17 PM

The reason it probably worked with PASV and not EPSV is because PASV includes a network address to connect to which in this case is probably a LAN address that is not blocked by a firewall. EPSV does not include an address so the data channel connects to the same IP address the control connection is connected to which might be a public address that is blocked by a firewall. Another reason is some NAT devices try to auto-magically detect FTP transfers and may work with PASV but not EPSV or vice-versa. Any how, this issue can usually be tracked back to a firewall or NAT device.

Jun 19, 2012 at 4:21 PM

Thanks for the explanation, I am definitely not a networking expert.

Jun 20, 2012 at 4:43 PM

This has popped up again, but with a different ftp site.  This time I was having an issue with a SSL certificate, but neither filezilla or IE, were asking for a certificate.  So, I found an old post that talked about ignoring when the InvalidCertificate event popped up.  http://netftp.codeplex.com/discussions/279814  Now I get past the error, but the GetListing hangs again and then times out.  Here is my output:

> 220 Serv-U FTP Server v5.0 for WinSock ready...
< AUTH TLS
> 234 AUTH command OK. Initializing SSL connection.
< PBSZ 0
> 200 PBSZ command OK. Protection buffer size set to 0.
< PROT P
> 200 PROT command OK. Using private data connection.
< USER aeci
> 331 User name okay, need password.
< PASS [omitted for security]
> 230 User logged in, proceed.
< CWD /mo/
> 250 Directory changed to /mo
< FEAT
> 211-Extension supported
>  AUTH TLS
>  SSCN
>  PBSZ
>  PROT
>  CLNT
>  MDTM
>  MDTM YYYYMMDDHHMMSS[+-TZ];filename
>  SIZE
>  SITE PSWD;EXEC;SET;INDEX;ZONE;CHMOD;MSG
>  REST STREAM
>  XCRC filename;start;end
> 211 End
< TYPE A
> 200 Type set to A.
< PASV
> 227 Entering Passive Mode (10,0,0,18,7,211)
> 421 Connection timed out - closing.

Coordinator
Jun 20, 2012 at 4:52 PM

Notice that the IP address in the PASV response is a private address. You can't connect to it over the internet. This is the drawback of using PASV (Passive) over EPSV (ExtendedPassive). Using PASV in the problem yesterday was only side stepping the real problem which seemed to be a firewall or ftp server configuration issue.

Jun 20, 2012 at 4:59 PM

Alright, I did a little investigating in FileZilla and found a new connection by default has Encryption to Use plain FTP.  I tried setting the SslMode = FtpSslMode.None, and now it works fine.  It doesn't even try to find a certificate so the first error goes away when i remove the ignoring code.