0

I'm using a socket to upload a file up to the server.

I'm using the STOR command to upload. Do I close the connection to cancel the upload or should I call QUIT?

    public static const STOR:String     = "STOR";
    public static const BINARY:String   = "TYPE I";
    public static const ASCII:String    = "TYPE A";
    public static const USER:String     = "USER";
    public static const PASS:String     = "PASS";
    public static const QUIT:String     = "QUIT";
    public static const CWD:String      = "CWD";
    public static const PWD:String      = "PWD";
    public static const LIST:String     = "LIST";
    public static const PASV:String     = "PASV";
    public static const RETR:String     = "RETR";
    public static const CD:String       = "CWD";

And related:

Will closing the socket cause someone to have to relogin? Is there a logout command?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231
  • 1
    My memory on FTP is shot, so I cant confidently write an answer, but in case no one else can give you answer I can tell you that generally, when I have written FTP script, I remember I have initiated 2 sockets, 1 for the file transfer when it starts and 1 "Control" Socket that Logs in and read the server responses etc. When the server is ready to recieve I initiated a new socket on a new thread for the transfer and sent `NOOP`s over the Control Socket to keep the Control connection alive – hammus Sep 12 '15 at 03:31
  • Like I said, my commenta above is not an answer but should point you in the right direction - here is a question I asked a while back (its for python but you might get some ideas for structure from it) http://stackoverflow.com/questions/19928061/ftplib-python-noop-command-works-in-ascii-not-binary – hammus Sep 12 '15 at 03:33
  • @leemo that's very helpful. the library i use creates a socket when i upload. it then closes it at the end after the data is sent. i can then upload another file willy nilly. so the first login connection must still be active. so it sounds like i would probably need to send noops to keep the original open then and closing the connection will log me out. – 1.21 gigawatts Sep 12 '15 at 03:40
  • Yeah I think that's the basic idea, I had alot of trouble keeping the Control connection alive, but it was largely to do with the python FTP library not really being designed for what I was trying to do. – hammus Sep 12 '15 at 03:41
  • 1
    For your reference: https://tools.ietf.org/html/rfc959 – alk Sep 12 '15 at 08:33

1 Answers1

1

In a common (default) stream FTP mode, there's no other way to terminate the transfer, than closing the data connection. You do not have to close the control connection, so you do not need to call QUIT either, so you do not need to re-login.

When uploading, the server won't even know that something went wrong. It will assume that the upload finished correctly (as closing the data connection is the only way to indicate complete upload in the stream mode). So you may consider explicitly removing the (partially) uploaded file, if you feel it is inappropriate to keep incomplete file on the server.


The other FTP transfer modes (block and compressed) do have a way to abort the transfer explicitly. But from my experience these modes are rarely used.
See Which FTP transfer modes are widely used?

Community
  • 1
  • 1
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992