Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
3k views
in .NET FTP by (360 points)
I've been able to connect to an FTP Server in Active mode through FileZilla, but unable to do the same with the .NET FTP library.

Here's my code:
_FtpConnection = 
   new FTPConnection
   {
      ServerAddress = ftpSite.FtpSite, 
      UserName = ftpSite.FtpUserID, 
      Password = ftpSite.FtpPassword, 
      Timeout = 10000,
      ConnectMode = FTPConnectMode.ACTIVE,
      PublicIPAddress = "my public ip"
   };
       
 _FtpConnection.ActivePortRange.LowPort = "6000";
 _FtpConnection.ActivePortRange.HighPort = "6001";
 _FtpConnection.ServerDirectory = "server directory";
 _FtpConnection.Connect();
 
 var files = _FtpConnection.GetFileInfos();
 
 _FtpConnection.Close();


Here's my log file. I've edited a few things to hide data. The remote IP has been replaced with "11.11.111.11", and my public IP in the PORT command has been replaced with "222,222,2,222".

DEBUG [FTPConnection] 6 Nov 2014 07:58:23.207 : Set LocalDirectory='C:\Windows\SysWOW64\inetsrv'
DEBUG [FTPClient] 6 Nov 2014 07:58:23.207 : Connecting to ftp.companyname.com:21
DEBUG [HostNameResolver] 6 Nov 2014 07:58:23.207 : Resolving ftp.companyname.com
DEBUG [HostNameResolver] 6 Nov 2014 07:58:23.363 : ftp.companyname.com resolved to 11.11.111.11
INFO [BaseSocket] 6 Nov 2014 07:58:23.363 : Connecting to 11.11.111.11:21 with timeout 10000 ms
DEBUG [BaseSocket] 6 Nov 2014 07:58:23.441 : Successfully connected to 11.11.111.11:21
DEBUG [FTPControlSocket] 6 Nov 2014 07:58:23.441 : Setting socket timeout=10000
INFO [FTPControlSocket] 6 Nov 2014 07:58:23.441 : Command encoding=System.Text.SBCSCodePageEncoding
DEBUG [FTPControlSocket] 6 Nov 2014 07:58:23.441 : SetActivePortRange(6000,6001). NextPort=6000
DEBUG [FTPControlSocket] 6 Nov 2014 07:58:23.441 : StrictReturnCodes=False
DEBUG [FTPControlSocket] 6 Nov 2014 07:58:23.519 : 220 (vsFTPd 2.2.2)
DEBUG [FTPConnection] 6 Nov 2014 07:58:23.534 : Connected to ftp.companyname.com (instance=0)
DEBUG [FTPControlSocket] 6 Nov 2014 07:58:23.534 : ---> USER my_username
DEBUG [FTPControlSocket] 6 Nov 2014 07:58:23.612 : 331 Please specify the password.
DEBUG [FTPControlSocket] 6 Nov 2014 07:58:23.612 : ---> PASS ********
DEBUG [FTPControlSocket] 6 Nov 2014 07:58:23.706 : 230 Login successful.
DEBUG [FTPConnection] 6 Nov 2014 07:58:23.706 : Successfully logged in
INFO [FTPConnection] 6 Nov 2014 07:58:23.706 : Auto FEAT disabled
DEBUG [FTPControlSocket] 6 Nov 2014 07:58:23.706 : ---> TYPE I
DEBUG [FTPControlSocket] 6 Nov 2014 07:58:23.784 : 200 Switching to Binary mode.
DEBUG [FTPControlSocket] 6 Nov 2014 07:58:23.800 : ---> CWD out
DEBUG [FTPControlSocket] 6 Nov 2014 07:58:23.878 : 250 Directory successfully changed.
DEBUG [FTPControlSocket] 6 Nov 2014 07:58:23.878 : ---> PWD
DEBUG [FTPControlSocket] 6 Nov 2014 07:58:23.956 : 257 "/out"
DEBUG [FTPControlSocket] 6 Nov 2014 07:58:23.956 : ---> SYST
DEBUG [FTPControlSocket] 6 Nov 2014 07:58:24.034 : 215 UNIX Type: L8
DEBUG [FTPFileFactory] 6 Nov 2014 07:58:24.034 : Selected UNIX parser
DEBUG [FTPControlSocket] 6 Nov 2014 07:58:24.034 : ---> PWD
DEBUG [FTPControlSocket] 6 Nov 2014 07:58:24.112 : 257 "/out"
DEBUG [FTPControlSocket] 6 Nov 2014 07:58:24.112 : NewActiveDataSocket(6000)
INFO [FTPControlSocket] 6 Nov 2014 07:58:24.112 : Forcing use of fixed IP for PORT command
DEBUG [FTPControlSocket] 6 Nov 2014 07:58:24.112 : ---> PORT 222,222,2,222,23,112
DEBUG [FTPControlSocket] 6 Nov 2014 07:58:24.190 : 200 PORT command successful. Consider using PASV.
DEBUG [FTPControlSocket] 6 Nov 2014 07:58:24.190 : Next active port will be: 6001
DEBUG [FTPControlSocket] 6 Nov 2014 07:58:24.190 : ---> LIST
ERROR [FTPControlSocket] 6 Nov 2014 07:58:34.694 : Read failed ('' read so far)
ERROR [FTPControlSocket] 6 Nov 2014 07:58:34.694 : Exception in SendCommand
ERROR [FTPControlSocket] 6 Nov 2014 07:58:34.694 : EnterpriseDT.Net.Ftp.ControlChannelIOException: Unable to read data from the transport connection: 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.
ERROR [FTPControlSocket] 6 Nov 2014 07:58:34.694 : at EnterpriseDT.Net.Ftp.FTPControlSocket.ReadLine()
ERROR [FTPControlSocket] 6 Nov 2014 07:58:34.694 : at EnterpriseDT.Net.Ftp.FTPControlSocket.ReadReply()
ERROR [FTPControlSocket] 6 Nov 2014 07:58:34.694 : at EnterpriseDT.Net.Ftp.FTPControlSocket.SendCommand(String command)


Any ideas what I'm doing wrong here, or why I can't connect?

9 Answers

0 votes
by (162k points)
Post the Filezilla debug log, and substitute the same IP addresses so we can compare them.
0 votes
by (360 points)
Here's the FileZilla log file:

2014-11-06 09:46:30 6740 1 Status: Resolving address of ftp.companyname.com
2014-11-06 09:46:31 6740 1 Status: Connecting to 11.11.111.11:21...
2014-11-06 09:46:31 6740 1 Status: Connection established, waiting for welcome message...
2014-11-06 09:46:31 6740 1 Response: 220 (vsFTPd 2.2.2)
2014-11-06 09:46:31 6740 1 Command: USER my_username
2014-11-06 09:46:31 6740 1 Response: 331 Please specify the password.
2014-11-06 09:46:31 6740 1 Command: PASS **********
2014-11-06 09:46:31 6740 1 Response: 230 Login successful.
2014-11-06 09:46:31 6740 1 Command: SYST
2014-11-06 09:46:31 6740 1 Response: 215 UNIX Type: L8
2014-11-06 09:46:31 6740 1 Command: FEAT
2014-11-06 09:46:31 6740 1 Response: 211-Features:
2014-11-06 09:46:31 6740 1 Response: EPRT
2014-11-06 09:46:31 6740 1 Response: EPSV
2014-11-06 09:46:31 6740 1 Response: MDTM
2014-11-06 09:46:31 6740 1 Response: PASV
2014-11-06 09:46:31 6740 1 Response: REST STREAM
2014-11-06 09:46:31 6740 1 Response: SIZE
2014-11-06 09:46:31 6740 1 Response: TVFS
2014-11-06 09:46:31 6740 1 Response: UTF8
2014-11-06 09:46:31 6740 1 Response: 211 End
2014-11-06 09:46:31 6740 1 Command: OPTS UTF8 ON
2014-11-06 09:46:31 6740 1 Response: 200 Always in UTF8 mode.
2014-11-06 09:46:31 6740 1 Status: Connected
2014-11-06 09:46:31 6740 1 Status: Retrieving directory listing...
2014-11-06 09:46:31 6740 1 Command: PWD
2014-11-06 09:46:32 6740 1 Response: 257 "/"
2014-11-06 09:46:32 6740 1 Command: TYPE I
2014-11-06 09:46:32 6740 1 Response: 200 Switching to Binary mode.
2014-11-06 09:46:32 6740 1 Command: PORT 222,222,2,222,23,112
2014-11-06 09:46:32 6740 1 Response: 200 PORT command successful. Consider using PASV.
2014-11-06 09:46:32 6740 1 Command: LIST
2014-11-06 09:46:32 6740 1 Response: 150 Here comes the directory listing.
2014-11-06 09:46:32 6740 1 Response: 226 Directory send OK.
2014-11-06 09:46:32 6740 1 Status: Directory listing successful
0 votes
by (360 points)
Sorry, that last log was just the part where I connect to the server. Here's the additional part where I open that specific folder:

2014-11-06 10:00:48 2088 1 Command: CWD out
2014-11-06 10:00:48 2088 1 Response: 250 Directory successfully changed.
2014-11-06 10:00:48 2088 1 Command: PWD
2014-11-06 10:00:48 2088 1 Response: 257 "/out"
2014-11-06 10:00:48 2088 1 Command: PORT 222,222,2,222,,23,112
2014-11-06 10:00:48 2088 1 Response: 200 PORT command successful. Consider using PASV.
2014-11-06 10:00:48 2088 1 Command: LIST
2014-11-06 10:00:48 2088 1 Response: 150 Here comes the directory listing.
2014-11-06 10:00:48 2088 1 Response: 226 Directory send OK.
2014-11-06 10:00:48 2088 1 Status: Calculating timezone offset of server...
2014-11-06 10:00:48 2088 1 Command: MDTM BSH_ONHAND_20141103215839.csv
2014-11-06 10:00:48 2088 1 Response: 213 20141104060003
2014-11-06 10:00:48 2088 1 Status: Timezone offsets: Server: 0 seconds. Local: -28800 seconds. Difference: -28800 seconds.
2014-11-06 10:00:48 2088 1 Status: Directory listing successful
0 votes
by (162k points)
That's unusual behavior. Are you sure there's not a local firewall preventing the server from connecting back to the active port, but with an exception for Filezilla?
0 votes
by (360 points)
I turned my firewall off and tried again, with the same result.
0 votes
by (162k points)
If you have access to the server logs that might give a clue. Basically, it looks like the server is unable to connect back to the client on that port number. It might help to allocate a large port number range.
0 votes
by (360 points)
I just had the same idea and allocated a range of 6000 - 7000. No change with that.
0 votes
by (360 points)
Ok, some new information.

I got this to work on my local machine when I didn't specify my public IP. However, my production environment is an Azure virtual machine, for which I will have to specify my public static IP, or else I get the error message "Illegal PORT command".
0 votes
by (360 points)
Solved my problem, and all the confusion was probably caused by my giving somewhat inaccurate information (sorry!).

The logs I showed above are from my Azure virtual machine, but then I also mentioned that I had turned the firewall off, which I had done on my local machine. So it eventually worked on my local machine when I fixed the public IP issue, and I now got it to work on the Azure virtual machine by setting up "endpoints" for the required ports in the Azure management portal, as well as creating an inbound rule in the Windows Firewall for traffic on the same ports, that comes from Port 20 on the remote machine.

Sorry for the confusion! Consider this resolved, and thank you for your help!

Categories

...