This project is read-only.

Unable to use Active Mode

Developer
Nov 30, 2011 at 11:45 AM
Edited Nov 30, 2011 at 11:52 AM

EDIT: Sorry, Just after posting I thought about the Windows FireWall, the application was not allowed. Everything works fine. Sorry again.

Hi, 

I'm doing some tests for an application I'm developping and I can't use active mode in some cases.

So, for example, I try to connect to ftp.mozilla.org, and use active mode, here is the ouput:

 

> 220-
> 220-   ftp.mozilla.org / archive.mozilla.org - files are in /pub/mozilla.org
> 220-
> 220-   Notice: This server is the only place to obtain nightly builds and needs to
> 220-   remain available to developers and testers. High bandwidth servers that
> 220-   contain the public release files are available at ftp://releases.mozilla.org/
> 220-   If you need to link to a public release, please link to the release server,
> 220-   not here. Thanks!
> 220-
> 220-   Attempts to download high traffic release files from this server will get a
> 220-   "550 Permission denied." response.
> 220 
< USER anonymous
> 331 Please specify the password.
< PASS [omitted for security]
> 230-
> 230-   ftp.mozilla.org / archive.mozilla.org - files are in /pub/mozilla.org
> 230-
> 230-   Notice: This server is the only place to obtain nightly builds and needs to
> 230-   remain available to developers and testers. High bandwidth servers that
> 230-   contain the public release files are available at ftp://releases.mozilla.org/
> 230-   If you need to link to a public release, please link to the release server,
> 230-   not here. Thanks!
> 230-
> 230-   Attempts to download high traffic release files from this server will get a
> 230-   "550 Permission denied." response.
> 230 Login successful.
< CWD /
> 250 Directory successfully changed.
< FEAT
> 211-Features:
>  EPRT
>  EPSV
>  MDTM
>  PASV
>  REST STREAM
>  SIZE
>  TVFS
> 211 End
< TYPE I
> 200 Switching to Binary mode.
< PORT 192,168,0,10,213,149
> 200 PORT command successful. Consider using PASV.
< LIST
> 150 Here comes the directory listing.

 

As you see, it get stuck on the last command and never get back.
I the code, it blocks in the Accept() method of the FtpActiveStream.cs file. For now I haven't been able to find why.

I have tested on some Ftp client to check if the problem could come from me trying to LIST using Active on servers asking for Passive,
but it works well with FileZilla and FlashFXP.

So if you have any idea, I'll be glad to ear it !

Thank you. 

Coordinator
Nov 30, 2011 at 1:50 PM

Hi,

This line here PORT 192,168,0,10,213,149 tells me you're using NAT and thus behind a router. A quick guess is that your router is not forwarding the appropriate port to the device attempting to establish the active connection. Try EPRT (ExtendedActive) instead and see if it works. Some home routers will detect ftp transactions and allow/forward ports as necessary. I suspect that may be why filezilla for example works behind your router with active mode transfers but I can't know for sure until you try it. All the same, it's hanging up waiting on the incoming data connection from the server which is a nat/firewall issue that you need to address in order to use the PORT command.

Hope this helps,

J.P.

Sep 19, 2012 at 7:18 AM
Edited Sep 19, 2012 at 7:20 AM

I also had an issue where my program becomes unresponsive when active mode is selected and I have SSL enabled. I am sure this is due to firewall. The accept blocks and never returns so you are forced to hard kill your application. I resolved this in the Accept method so it will at least time out, even though you are not able to get a connection on the data channel at least the program is not hung waiting for a connection on the data channel.

EDIT: Forgot this is in the class FtpActiveStream

/// <summary>
/// Accepts the incomming connection
/// </summary>
protected void Accept() {

//don't want it to hang if server cannot make connection to our data port
IAsyncResult result = this.Socket.BeginAccept((IAsyncResult callback) =>
            {
                this.Socket = this.Socket.EndAccept(callback);
            }, this.Socket);

result.AsyncWaitHandle.WaitOne(this.ControlConnection.DataChannelReadTimeout);
//if async result did not complete throw IOException
if (!result.IsCompleted) throw new System.IO.IOException("Data channel failed to connect before timeout occurred.");

}
Coordinator
Sep 20, 2012 at 9:18 PM

This problem should be addressed with the new DataChannelConnectionTimeout property available as of revision af4c969cce12.