+1 vote
by (180 points)

Exception: Error source 'Folder' on GetList()
Inner Exception
FtpException : An existing connection was forcibly closed by the remote host.
at Rebex.Net.Ftp.GM(Int32 A, Boolean B)
at Rebex.Net.Ftp.KM(EndPoint A)
at Rebex.Net.Ftp.SM(String A, Boolean B, VS C, WP D, Int64 I, FtpTransferState J)
at Rebex.Net.Ftp.PO(String A, Boolean B, Stream C, Int64 D, String I, WP J)
at Rebex.Net.Ftp.VO(String A, WP B)
at Rebex.Net.Ftp.GetList(String arguments)
at Rebex.Net.Ftp.ZI()

Unsecured connection, Active/Passive doesn't matter

Any ideas? Thanks!

Applies to: Rebex FTP/SSL

1 Answer

0 votes
by (58.9k points)

A communication log would reveal more information about what was going on before the server has closed the connection.

Once you have the log, please either post it here, or send it to support@rebex.net for analysis.

The connection could have been closed by some firewall or ill-behaved network device as well but this is just a guess.

To know even more you would have to dive deeper and capture packets with Wireshark both at the client and server-side.

by (180 points)
here's the more info form log

2015-12-03 09:35:59.047 INFO Ftp(26)[5] Response: 250 CWD command successful.
2015-12-03 09:35:59.047 DEBUG Ftp(26)[5] Info: Starting data transfer.
2015-12-03 09:35:59.047 INFO Ftp(26)[5] Command: TYPE A
2015-12-03 09:35:59.068 INFO Ftp(26)[5] Response: 200 Type set to A.
2015-12-03 09:35:59.068 DEBUG Ftp(26)[5] Info: Accepting data connection.
2015-12-03 09:35:59.070 INFO Ftp(26)[5] Command: PORT 10,10,20,5,167,155
2015-12-03 09:36:17.968 DEBUG Ftp(26)[5] Info: Control connection failed, closing current data connection.
2015-12-03 09:36:17.971 DEBUG Ftp(26)[5] Info: Error while starting data transfer: Rebex.Net.FtpException: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at Rebex.Net.ProxySocket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at Rebex.Net.IS.BC()
   at Rebex.Net.IS.BC(Int32 A)
   at Rebex.Net.IS.GC(String& A, Int32 B)
   at Rebex.Net.IS.HC(Int32 A)
   at Rebex.Net.Ftp.GM(Int32 A, Boolean B)
   --- End of inner exception stack trace ---
   at Rebex.Net.Ftp.GM(Int32 A, Boolean B)
   at Rebex.Net.Ftp.KM(EndPoint A)
   at Rebex.Net.Ftp.SM(String A, Boolean B, VS C, WP D, Int64 I, FtpTransferState J)
2015-12-03 09:36:17.971 ERROR Ftp(26)[5] Info: Rebex.Net.FtpException: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at Rebex.Net.ProxySocket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at Rebex.Net.IS.BC()
   at Rebex.Net.IS.BC(Int32 A)
   at Rebex.Net.IS.GC(String& A, Int32 B)
   at Rebex.Net.IS.HC(Int32 A)
   at Rebex.Net.Ftp.GM(Int32 A, Boolean B)
   --- End of inner exception stack trace ---
   at Rebex.Net.Ftp.GM(Int32 A, Boolean B)
   at Rebex.Net.Ftp.KM(EndPoint A)
   at Rebex.Net.Ftp.SM(String A, Boolean B, VS C, WP D, Int64 I, FtpTransferState J)
   at Rebex.Net.Ftp.PO(String A, Boolean B, Stream C, Int64 D, String I, WP J)
2015-12-03 09:36:17.971 ERROR Ftp(26)[5] Info: Rebex.Net.FtpException: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at Rebex.Net.ProxySocket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)

Why does it happen?
by (58.9k points)
edited by
PORT 10,10,20,5,167,155 command indicates that the client is using active mode FTP and it is instructing the FTP server to connect to the client machine at 10.10.20.5 to establish a data connection.

Where are the FTP client and FTP server located? If the server is a server on the Internet, this is not going to work because the client runs in a private network (using 10.0.0.0/8 range). For active mode to work, client's IP address must be reachable by the server. However, this is most likely not the case because the server closed the connection after receiving the PORT command asking it to connect to an unreachable IP.

Active mode FTP is notorious for being extremely firewall unfriendly. Getting Passive mode to work is usually much easier:

            Ftp ftp = new Ftp();
            ftp.Passive = true;

            ftp.Connect("server");
            ftp.Login("user", "password");

            ftp.GetList();

            ftp.Disconnect();

In passive mode, the FTP client connects to the server to initiate data transfers Give the above code a try and see whether you get through with the Passive property set to true.
...