Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of FTP "append" command

I want to upload a file to a ftp server programmatically (C++). If the connection is lost while uploading a file, I wouldn't want to upload the file from scratch, but to upload only the part that I haven't sent.

Does the APPE command fulfill my demand? What list of FTP commands should I use exactly? And how?

like image 976
Feyyaz Avatar asked Dec 29 '25 19:12

Feyyaz


1 Answers

I am googling details about APPE FTP command, what actually it does but most site just state only append. Then I try out the command to make sure it behave as expected.

I designing FTP auto sender that is used to send a log file from a machine to a server for reporting. I only want to send the last line of the log file.

When using a APPE command, it actually append the whole file content and append to the existing one in the server. This will cause the line entry duplicated.

The answer: To do the resume of file if the last transfer is failed, there is no such command for that, but we need to use a sequence of command to achieve it.

The key point here is seek your local file to the last uploaded byte if you are using APPE command or using command REST. REST will start transfer on that particular byte start position. I end-up with this solution to perform after connection established:

Use APPE (I got the idea from FileZilla log):

  1. Use SIZE to check for file exist and use it as resume marker.
  2. Open local file system and seek on the marker.
  3. Use APPE to upload and FTP server will append it automatically.

Use STOR with REST (I got the idea from edtFTPnet):

  1. Use SIZE to check for file exist and use it as resume marker.
  2. Send REST with the result you get from SIZE to tell FTP server to start write on the position.
  3. Open local file system and seek on the marker.
  4. Use STOR as normal upload.

Note that not all FTP server support for both way. I see FileZilla switch this two way depending on the server. My observation shows that using REST is the standard way. Download can also use REST to start download on the given byte position.

Remember that using resume support for ASCII transfer type will produce unexpected result since Unix and Windows have different line break byte count.

Try to manipulate FileZilla to see the behave in the log. You can also check this useful open source FTP for .NET library on how they do it. edtFTPnet

like image 182
CallMeLaNN Avatar answered Jan 01 '26 08:01

CallMeLaNN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!