7

From the command line, I want to download a file from a FTP server. Once the download completes, I want the file to be deleted on the server. Is there any way to do this?

Originally I considered wget, but there is no particular reason why to use that specifically. Any tool would be fine as long as it runs on Linux.

  • 1
    Not with wget, no. – roaima Mar 17 '15 at 20:50
  • 3
    If there is a "why" you have to use wget, please, edit your question and explain ;) – user34720 Mar 17 '15 at 21:34
  • Hi andy_ttse, and welcome to the site. I edited your question to hopefully make it more clear. I believe I stayed true to your intent, but also recognize that it is a fairly large edit; should you be unhappy with the edit for any reason whatsoever, by all means feel free to either edit further, or to roll back my edit. (Click the "edited ... ago" link, then click "rollback" above the revision you want to roll back to.) Remember that the full edit history for each post is available, so unlike on most forums, there's usually no reason to not make any changes inline. – a CVn Mar 17 '15 at 22:13
  • I would think using regular ftp commands would be fine. get filename mdelete filename Or are you asking how to do it all from one line? – No Time Mar 18 '15 at 0:27
8

with curl:

curl ftp://example.com/ -X 'DELE myfile.zip' --user username:password
  • curl command above only deletes the file. If you'd like to use retrieve and delete in a single step, use: curl -O example.com/myfile.zip -Q '-rm myfile.zip' --user username:password – shpokas Dec 6 '16 at 5:36
6

with lftp:

lftp ftp://user:password@host -e "get -E remotefile; bye"
0

For multiple files using lftp:

lftp ftp://user:password@$host -e "mirror --Remove-source-files; bye"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.