0 votes
by (2.0k points)
edited by

While GetFile(name, stream) function running,
I want to cancel download only.
But I guess that ftp.Abort() function drops main control connection.
(next ftp.GetFile() raise 'Not connected to the server' exception.)
I want to keep main control connection and only cancel current download.

Thank you.
(Sorry my poor English)

Applies to: Rebex FTP/SSL

1 Answer

+1 vote
by (73.6k points)
selected by
 
Best answer

Hello,

the ftp.Abort() method invokes ABOR command (RFC 959):

... The control connection is not to be closed by the server, but the data connection must be closed."

Unfortunately, some FTP servers cannot handle this command appropriately and closes the control connection as well.

If you want to diagnose what is going on with your server, please create communication log. If you need help with diagnosing post the log here or send it to support@rebex.net.

If it shows that the client closes the control connection, it is a bug in FTP client.
If it shows that the server closes the connection, it is bug in FTP server and the server has to be fixed (it cannot be workarounded on client side).

by (2.0k points)
I added logging and test.
Synology FTPS server do not answer the command Abort duning 10 seconds. (AbortTimeout = 10000)
log:
2017-08-04 13:31:21.662 Opening log file.
2017-08-04 13:31:21.662 Using FileLogWriter version 2.5.6391.0.
2017-08-04 13:31:21.662 INFO RaiFtp(55)[19] Info: Connecting to raidrive.synology.me:921 using Ftp.
2017-08-04 13:31:21.662 INFO RaiFtp(55)[19] Info: Assembly: Rebex.Ftp 2017 R4 for .NET 4.0-4.7 (Trial)
2017-08-04 13:31:21.662 DEBUG RaiFtp(55)[19] Info: Platform: Windows 10.0.15063 64-bit; CLR: 4.0.30319.42000
2017-08-04 13:31:21.662 DEBUG RaiFtp(55)[19] Info: Culture: ko; ks_c_5601-1987
2017-08-04 13:31:21.662 INFO RaiFtp(55)[19] Info: Using proxy none.
2017-08-04 13:31:21.662 DEBUG ProxySocket(178)[19] Socket: Resolving 'raidrive.synology.me'.
2017-08-04 13:31:21.662 DEBUG ProxySocket(178)[12] Socket: Connecting to 210.106.56.71:921.
2017-08-04 13:31:21.672 DEBUG RaiFtp(55)[19] Info: Connection succeeded.
2017-08-04 13:31:21.687 INFO RaiFtp(55)[19] Response: 220 here FTP server ready.
2017-08-04 13:31:21.687 INFO RaiFtp(55)[19] Command: AUTH TLS
...
2017-08-04 13:31:21.731 INFO RaiFtp(55)[19] TLS: Connection secured using cipher: TLS 1.2, RSA, 256bit AES in CBC mode, SHA256
2017-08-04 13:31:21.731 DEBUG RaiFtp(55)[19] TLS: Session ID:
 0000 |7D-0B-D8-35-B4-74-95-6F 48-FB-3B-1C-32-62-ED-77| }..5.t.oH.;.2b.w
 0010 |88-2F-6F-C9-BA-2A-63-CC 4B-26-88-A7-18-80-6A-F3| ./o..*c.K&....j.
2017-08-04 13:31:21.731 DEBUG RaiFtp(55)[19] Info: Control connection upgraded to TLS/SSL.
2017-08-04 13:31:21.731 INFO RaiFtp(55)[19] Command: USER lanopk
...
2017-08-04 13:31:22.045 INFO RaiFtp(55)[19] Command: OPTS UTF8 ON
2017-08-04 13:31:22.053 INFO RaiFtp(55)[19] Response: 200 OK, UTF-8 enabled
2017-08-04 13:31:22.059 DEBUG RaiFtp(55)[19] Info: Starting data transfer.
2017-08-04 13:31:22.059 INFO RaiFtp(55)[19] Command: PBSZ 0
2017-08-04 13:31:22.078 INFO RaiFtp(55)[19] Response: 200 PBSZ command successful (PBSZ=0).
2017-08-04 13:31:22.078 INFO RaiFtp(55)[19] Command: PROT P
2017-08-04 13:31:22.088 INFO RaiFtp(55)[19] Response: 200 Protection level set to Private.
2017-08-04 13:31:22.088 INFO RaiFtp(55)[19] Command: TYPE I
2017-08-04 13:31:22.104 INFO RaiFtp(55)[19] Response: 200 Type set to I.
2017-08-04 13:31:22.104 INFO RaiFtp(55)[19] Command: PASV
2017-08-04 13:31:22.112 INFO RaiFtp(55)[19] Response: 227 Entering Passive Mode (192,168,200,40,216,242)
2017-08-04 13:31:22.112 INFO RaiFtp(55)[19] Info: Using server address 210.106.56.71 instead of received address 192.168.200.40.
2017-08-04 13:31:22.112 INFO RaiFtp(55)[19] Command: REST 253755392
2017-08-04 13:31:22.140 INFO RaiFtp(55)[19] Response: 350 Restarting at 253755392. Send STORE or RETRIEVE to initiate transfer.
2017-08-04 13:31:22.140 DEBUG RaiFtp(55)[19] Info: Establishing data connection to 210.106.56.71:55538.
2017-08-04 13:31:22.140 DEBUG ProxySocket(182)[19] Socket: Connecting to 210.106.56.71:55538.
2017-08-04 13:31:22.149 DEBUG RaiFtp(55)[19] Info: Established data connection from 192.168.0.19:6823.
2017-08-04 13:31:22.149 INFO RaiFtp(55)[19] Command: RETR /Test/ReadWrite/TestFile.mp4
2017-08-04 13:31:22.163 INFO RaiFtp(55)[19] Response: 150 Opening BINARY mode SSL data connection for '/Test/ReadWrite/TestFile.mp4' (256197311 bytes).
2017-08-04 13:31:22.163 DEBUG RaiFtp(55)[19] Info: Upgrading data connection to TLS/SSL.
2017-08-04 13:31:22.163 DEBUG RaiFtp(55)[19] TLS: Data connection: Asking the server to resume session ID:
 0000 |7D-0B-D8-35-B4-74-95-6F 48-FB-3B-1C-32-62-ED-77| }..5.t.oH.;.2b.w
 0010 |88-2F-6F-C9-BA-2A-63-CC 4B-26-88-A7-18-80-6A-F3| ./o..*c.K&....j.
2017-08-04 13:31:22.163 INFO RaiFtp(55)[19] TLS: Data connection: State StateChange:Negotiating
...
2017-08-04 13:31:22.182 DEBUG RaiFtp(55)[19] TLS: Data connection: Session ID:
 0000 |7D-0B-D8-35-B4-74-95-6F 48-FB-3B-1C-32-62-ED-77| }..5.t.oH.;.2b.w
 0010 |88-2F-6F-C9-BA-2A-63-CC 4B-26-88-A7-18-80-6A-F3| ./o..*c.K&....j.
2017-08-04 13:31:22.182 DEBUG RaiFtp(55)[19] Info: Data connection upgraded to TLS/SSL.
2017-08-04 13:31:24.974 INFO RaiFtp(55)[19] Info: Aborting operation.
2017-08-04 13:31:24.977 DEBUG RaiFtp(55)[19] Info: Aborting downloading data connection.
2017-08-04 13:31:24.977 INFO RaiFtp(55)[19] Info: Aborting download.
2017-08-04 13:31:24.977 INFO RaiFtp(55)[19] Command: ABOR
2017-08-04 13:31:35.981 INFO RaiFtp(55)[19] Info: Timing out because of an abort method.
2017-08-04 13:31:35.981 DEBUG RaiFtp(55)[19] Info: Unable to abort, closing data connection instead.
2017-08-04 13:31:35.981 DEBUG RaiFtp(55)[19] TLS: Data connection: Closing TLS socket.
2017-08-04 13:31:35.981 INFO RaiFtp(55)[19] TLS: Data connection: Alert Alert:Alert was sent.
2017-08-04 13:31:35.981 INFO RaiFtp(55)[19] TLS: Data connection: State StateChange:Closed
2017-08-04 13:31:35.992 DEBUG RaiFtp(55)[19] TLS: TLS socket error, 0 bytes of data were received.
2017-08-04 13:31:35.992 DEBUG RaiFtp(55)[19] TLS: TLS socket was closed: System.Net.Sockets.SocketException (0x80004005): 현재 연결은 원격 호스트에 의해 강제로 끊겼습니다 => means : current connection was closed forcely by remote host.
   위치: System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   위치: Rebex.Net.BPW.RX(Int32 D)
   위치: Rebex.Net.BPW.HX()
   위치: Rebex.Net.BPW.UX()
2017-08-04 13:31:35.992 INFO RaiFtp(55)[19] TLS: Alert Alert:Alert was sent.
2017-08-04 13:31:35.992 INFO RaiFtp(55)[19] TLS: State StateChange:Closed
2017-08-04 13:31:35.992 DEBUG RaiFtp(55)[19] Info: Control connection was forcibly closed.
2017-08-04 13:31:35.992 DEBUG RaiFtp(55)[19] TLS: Closing TLS socket.
2017-08-04 13:31:35.993 ERROR RaiFtp(55)[19] Info: Error while closing data connection: Rebex.Net.FtpException: The server has closed the connection. ---> Rebex.Net.FtpException: The server has closed the connection. ---> Rebex.Net.TlsException: Connection was closed by the remote connection end. ---> System.Net.Sockets.SocketException: 현재 연결은 원격 호스트에 의해 강제로 끊겼습니다
   위치: System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   위치: Rebex.Net.BPW.RX(Int32 D)
   위치: Rebex.Net.BPW.HX()
   위치: Rebex.Net.BPW.UX()
   --- 내부 예외 스택 추적의 끝 ---
   위치: Rebex.Net.BPW.UX()
   위치: Rebex.Net.TlsSocket.Poll(Int32 microSeconds, SocketSelectMode mode)
   위치: Rebex.Net.QXW.XT(Int32 D)
   --- 내부 예외 스택 추적의 끝 ---
   위치: Rebex.Net.QXW.XT(Int32 D)
   위치: Rebex.Net.QXW.LT(String& D, Int32 N)
   위치: Rebex.Net.QXW.AT(Int32 D)
   위치: Rebex.Net.Ftp.DM(Int32 D, Boolean N)
   위치: Rebex.Net.Ftp.RM(HOW D, Int64 N, Boolean T)
   --- 내부 예외 스택 추적의 끝 ---
   위치: Rebex.Net.Ftp.RM(HOW D, Int64 N, Boolean T)
   위치: Rebex.Net.HOW.ZW()
2017-08-04 13:31:36.018 ERROR RaiFtp(55)[19] Info: System.InvalidOperationException: Not connected to the server.
   위치: Rebex.Net.Ftp.TR()
   위치: Rebex.Net.Ftp.BM(String D, SeekOrigin N, Int64 T)
2017-08-04 13:31:38.047 ERROR RaiFtp(55)[19] Info: System.InvalidOperationException: Not connected to the server.
   위치: Rebex.Net.Ftp.TR()
   위치: Rebex.Net.Ftp.BM(String D, SeekOrigin N, Int64 T)
2017-08-04 13:31:42.063 ERROR RaiFtp(55)[19] Info: System.InvalidOperationException: Not connected to the server.
   위치: Rebex.Net.Ftp.TR()
   위치: Rebex.Net.Ftp.BM(String D, SeekOrigin N, Int64 T)
2017-08-04 13:31:50.079 ERROR RaiFtp(55)[19] Info: System.InvalidOperationException: Not connected to the server.
   위치: Rebex.Net.Ftp.TR()
   위치: Rebex.Net.Ftp.BM(String D, SeekOrigin N, Int64 T)
2017-08-04 13:32:06.096 ERROR RaiFtp(55)[19] Info: System.InvalidOperationException: Not connected to the server.
   위치: Rebex.Net.Ftp.TR()
   위치: Rebex.Net.Ftp.BM(String D, SeekOrigin N, Int64 T)
by (73.6k points)
Thank you for the log. It really seems that the server doesn't support ABOR command correctly.

When there is no response for ABOR command for specified time, we closes the data connection (which is not designated in RFC, but it is most reasonable action when client wants to abort the current transfer and server doesn't support it). In some cases, FTP server just discards closed data connection and keeps the control connection.

Unfortunately, you have second kind of FTP server. When data connection is closed, server closes the control connection as well.

Conclusion:
When using this Synology FTPS server, Abort method doesn't work. Instead, dispose the FTP client object and reconnect.
...