0

I need to pull files from an ftp server regularly and have found that I can get the files easily enough using wget

wget -m --user=yyy --password=xxxx ftps://host.com.au

and that works really nicely. The problem is, it obviously leaves the files behind on the remote server and the next time I run the script, it gets them all again.

I saw that wget has a --delete-after flag, which on first glance would seem to be ideal, but, as the man page says, it only deletes local files not remote ones.

Is there a way to achieve this end? It needs to be via ftp unfortunately as I don't have shell access or rsync access to the remote server. Should I be looking at something other than wget?

Romeo Ninov
  • 5,263
  • 4
  • 20
  • 26
Peter Nunn
  • 452
  • 1
  • 11
  • 25
  • Why are you using wget instead of an ftp client, which would be more likely to have this feature? – Appleoddity Apr 06 '22 at 04:20
  • Good question. I can use filzilla or some such to achieve the outcome I'm after, but, I need to be able to script this so that I can run it from cron each day. – Peter Nunn Apr 06 '22 at 08:23
  • Have you consider using `lftp`? – Romeo Ninov Apr 06 '22 at 08:45
  • 1
    Hi @RomeoNinov can you please change your comment to an answer. I'ts 90% working so I should give you the benefit of status :) All I need to work out is how to have mirror leave the remote directories intact and just remove the files lftp ftp://site.com --user PW --password blah -e "mirror --Remove-source-files --verbose; bye" removes files and directories when its done transferring. – Peter Nunn Apr 09 '22 at 07:28

1 Answers1

2

Instead of wget you can try lftp. Command like:

 lftp site.com --user <username> --password <password> -e "mirror --Remove-source-files -v

in this command -e "mirror is used to do a mirror or remote site

--Remove-source remove the source files after download. Be very careful with this command

Romeo Ninov
  • 5,263
  • 4
  • 20
  • 26
  • 1
    Thanks for the answer. As I said in the comment above, --Remove-source does remove the source files which is great, but it also removes the directories in the entire directory tree which is not really what I want it to do, just remove the .csv files in the various directories. – Peter Nunn Apr 09 '22 at 09:52