This project is read-only.

If use Passive type, it will return below error message

Jul 20, 2011 at 4:29 PM

ftp.DefaultDataMode = System.Net.FtpClient.FtpDataMode.Active;

If use above , there is no any problem,

if use default, it will appear below error message, and when execute ftp.CurrentDirectory.Files, It appear error, the message is below,  I have use other ftp program, there is no any problem

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond *.*.*.**:6119

   at System.Net.Sockets.Socket.Connect(IPAddress[] addresses, Int32 port)
   at System.Net.Sockets.Socket.Connect(String host, Int32 port)
   at System.Net.FtpClient.FtpChannel.Connect()
   at System.Net.FtpClient.FtpDataChannel.Connect()
   at System.Net.FtpClient.FtpCommandChannel.OpenExtendedPassiveChannel()
   at System.Net.FtpClient.FtpCommandChannel.OpenDataChannel(FtpDataMode mode, FtpTransferMode xfer)
   at System.Net.FtpClient.FtpCommandChannel.OpenDataChannel(FtpTransferMode xfer)
   at System.Net.FtpClient.FtpClient.GetRawListing(String path, FtpListType type)
   at System.Net.FtpClient.FtpClient.GetListing(String path, FtpListType type)
   at System.Net.FtpClient.FtpClient.GetListing(String path)
   at System.Net.FtpClient.FtpDirectory.LoadListing()
   at System.Net.FtpClient.FtpDirectory.get_Files()

Jul 20, 2011 at 4:49 PM

In FtpCommandChannel.cs in the OpenDataChannel method, try changing this code (from the swtich/case):

if (this.HasCapability(FtpCapability.EPSV)) {
ch = this.OpenExtendedPassiveChannel();
else {
ch = this.OpenPassiveChannel();

to just this:

ch = this.OpenPassiveChannel();

If your server is behind a firewall or NAT device and without getting more debugging information, I think that what may be happening is that some firewalls will detect EPSV or PASV and open up ports as necessary. Some work with EPSV and some work with PASV. I have a router at home that only works properly with EPSV for example.

If this does not narrow down the problem I'll need to know the exact OS and exactly what ftp server software and version you're connecting to so that I can debug it myself.

Jul 20, 2011 at 5:01 PM

Please be sure to let me know your findings no matter if using PASV over EPSV fixes it or not.

Jul 21, 2011 at 2:07 AM

Dear Sir,

Thanks, I follow you instruction, I remove some ExtendedPassive Channel code, the program can work pretty.

Below is the return Message Array when execute the FEAT

 LANG zh-TW;fr-FR;ja-JP;it-IT;zh-CN;ru-RU;ko-KR;en-US;bg-BG
 MFF modify;;UNIX.mode;
 MLST modify*;perm*;size*;type*;unique*;*;UNIX.mode*;UNIX.owner*;


FYI: Original I tried, in my local server, there is no problem,  but connect to other server which is our partner ftp server appeared, I don't know whether the ftp server behind the fireware.

Jul 21, 2011 at 2:11 AM

Alright. Some servers support EPSV but don't report in the FEAT list and since EPSV is newer and generally better the code assumes it supports it and falls back to PASV if it gets an error response from the EPSV command. I'll work on some modifications that let you select which mode to use. I'll post back here with a description of what I decide to do so you can update your code accordingly.

Jul 21, 2011 at 2:26 AM

Alright I've commited a few changes. As far as your code goes, you should use the FtpDataMode.Passive which will cause PASV to be used instead EPSV. The default is still ExtendedPassive (EPSV). Updating your code will alow you to get future commits without worrying about it breaking due to the modifications I asked you to previously make. Thanks for posting back and I hope this helps outs.


Jul 21, 2011 at 2:34 AM

Dear Sir,

I think you should change from

this.Capabilities = FtpCapability.EPSV | FtpCapability.EPRT;


this.Capabilities = FtpCapability.EPRT;

in function LoadCapabilities(). 

Jul 21, 2011 at 2:42 AM

That doesn't help people that want to use EPSV when the server doesn't report it in the FEAT list. 9 times out 10 people are going to want to use what works and EPSV works on modern implementations and with modern routers and firewalls that filter for FTP transactions on the fly. The fact is, this rare instance where the EPSV connection times out it is the odd-ball case. I will not change the code as you are suggesting without more proof that EPSV is a problem and PASV should be used by default. FYI, PASV brings a new set of problems. PASV behind NAT for example will report an IP address that is possibly on a private network. The code could of course ignore the IP address and just connect to said port on the same IP as the server it's already connected but then we are not following the protocol and are opening up a new can of worms for people that need the code to follow the protocol. Again, I'm not going to change the way it works short of what I've already done which is to allow you to override the behavior the ftp client code has been using.

Thanks for your suggestions all the same.

Jul 21, 2011 at 3:58 AM


Noted for your consideration.