5

i am doing small ftp client for recieving some big files from ftp. I have read in RFC that ABOR command is very problematic for servers. Almost all servers i see just continue to send data even after ABOR sent through control connection. Closing the data transfer can result (in 70% of tests) in closing control connection also. The server just sends FIN packet after my pushed ABOR packet. What is the best good method to stop recieving at some byte and not lose the control connection? FlashFXP doing this ok on all types of connection delays and servers. While investigating tcp traffic i found standard ftp rfc flow.

But in my case still no success to abort transfer using this technique:

1) shutdown(passive_socket, SD_BOTH)

2) closesocket(passive_socket);

3) send(control_socket,"ABOR\r\n")

4) recv(control_socket) - stalled here

Thank you

Sergey
  • 685
  • 2
  • 8
  • 30

2 Answers2

6

The "ABOR\r\n" command should be sent as out-of-band data. In case of send() -

send(control_socket, "ABOR\r\n", 6, MSG_OOB);

Some time after you recv() code 426 Transfer aborted. Data connection closed.

The following link is more helpful if you can't achieve success aborint transfer: http://www.developer.nokia.com/Community/Discussion/showthread.php?134079-Telnet-quot-Interrupt-Process-quot-(IP)-signal-amp-Telnet-quot-Synch-quot

Sergey
  • 685
  • 2
  • 8
  • 30
  • 1
    I've been reading about OOB data in [another question on SO](http://stackoverflow.com/questions/589928/socket-programming-how-do-i-handle-out-of-band-data/591104#591104) and they also mention this use case as a typical use of OOB data. However, I'm confused as to why this is necessary (or even recommended) given that it seems to rely on a specific server architecture. If the server is properly listening on the control connection and processes `ABOR`command, it can just shutdown the data connection socket or stop sending, can't it? – André Caron Jul 16 '11 at 17:23
  • 1
    @André, out of band data is descriebed : "Urgent data" notifies the receiving connection that the separate stream is more important than the main stream. Therefore it must first check the separate stream in order to process the main stream normally. But in real world it means (as i think) just sending data TCP packet with PSH set no matter of window size or other things. I confused too because this is only related to FTP protocol i found first. – Sergey Jul 16 '11 at 19:51
  • I understand how it works. However, if you respect the control connection state from the client program, you shouldn't have *anything* in the control connection's input buffer on the server side when `ABOR` reaches the server. If using OOB has an impact on the speed of interpretation of this command, then I would understand that the data connection stops sending data faster. However, using OOB doesn't explain how it will cause the `ABOR` command to be interpreted (VS not at all, as in OP's case) on *any* given FTP server implementation. – André Caron Jul 16 '11 at 20:21
  • Maybe this is specific to the server implementation you are connecting to. Can you mention which FTP server you're using? – André Caron Jul 16 '11 at 20:23
  • I am using now 'FreeBSD vm1 7.4-PRERELEASE FreeBSD' /usr/libexec/ftpd. standard ftp server for unix/linux os. But i did not made other tests well, so maybe you're right.The code i took about oob data is from /usr/src/usr.sbin/lukemftp (symlink from standard ftp client on unix/linux). – Sergey Jul 16 '11 at 20:37
  • @Sergey The link in the answer does not exist any more. Can you provide an alternative? – nsane Aug 03 '16 at 13:07
0

You should not lose your control connection when closing the data transfer connection, they are two separate sockets. Maybe check your code to see why the control connection is being closed.

Rocky Pulley
  • 22,531
  • 20
  • 68
  • 106
  • I checked several times, under freebsd the standalone ftpd server just sends FIN packet, then when my client want to sends something to control socket the server sends RST. – Sergey Jun 23 '11 at 16:14
  • Another option is to have your code auto-reconnect on these disconnects. I have noticed that FileZilla does this. – Rocky Pulley Jun 23 '11 at 16:21
  • That is i am doing now, but this is really takes long time. the code interfere with windows drivers and i can't do such delays. I am using this code to send ABOR command- sprintf(tb, "%c%c%c%c%cABOR\r\n", 0xff, 0xf4, 0xff, 0xfd, 0x06); As descriebed in RFC, ABOR command may require special processing (the codes ctrl-c) – Sergey Jun 23 '11 at 16:31
  • Well, the problem is that when you have to deal with other servers which you can't control you kind of have to conform your code to their behavior. Maybe you should look into something other than FTP if that's an option. – Rocky Pulley Jun 23 '11 at 16:36
  • Yes i have planes about that, but for yet that is my dilemma, how to do this with FTP. – Sergey Jun 23 '11 at 16:47
  • 1
    If the goal is performance, I would highly suggest not using FTP. – Rocky Pulley Jun 23 '11 at 16:49