How can I download the latest file available in ftp server using wget. If I am using the below command it is giving all the files.
wget ftp://id:password@ftpserver/dir/*
Regards, Ram.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityHow can I download the latest file available in ftp server using wget. If I am using the below command it is giving all the files.
wget ftp://id:password@ftpserver/dir/*
Regards, Ram.
The answer is that you probably can't do this using just wget or any other single tool that I am aware of.
What you probably need to do is write a script that will use wget/curl/whatever that will request a directory listing from the ftp server. Then the script will select and retrieve the right file based on the file's name, or some other criteria.
Just add the "-N" option to wget to ignore files older than what you have locally. You could also add the "-nc" to completely skip a file if it already exists, even if the one on FTP is newer.
wget -N ftp://id:password@ftpserver/dir/*
My Solution is this:
curl 'ftp://server.de/dir/'$(curl 'ftp://server.de/dir/' 2>/dev/null | tail -1 | awk '{print $(NF)}')
Try to specify the file you want to download. Using '*' will download every file in the directory 'dir'.
Example:
wget ftp://gnjilux.cc.fer.hr/welcome.msg
...will download exactly the file 'welcome.msg' from the mentioned server.
Check the Wget-Manual.
Update: I'm not sure if I get your problem. Are you trying to sync the content of the remote server (machine running the FTP daemon) with your local server? Are you looking for something like rsync functionality over FTP? If yes, you could try ftpsync (wget alone won't help in this case).
Maybe my non-ideal but simple solution will be useful for somebody.
First, I've installed proftpd. Here is /ftp directory tree example:
/ftp/
/ftp/file1
/ftp/file1/subfile1
/ftp/file1/subfile2
/ftp/file2
Then I added task in crontab to execute every minute this script:
PACKAGES=$(find /ftp/* -type d -not -name 'lost+found')
for PACKAGE in "${PACKAGES[@]}"; do
echo $(ls -I 'latest' -Atp "${PACKAGE}" | grep -v '/' | head -n 1) > "${PACKAGE}"/latest
done
So for every file (or package in my case) you need to create individual directory and there will be file 'latest' that contains name of latest file in that directory. If you want to get latest version of some file then you can just execute command:
wget ftp://"${FTP_SRV}"/"${FILE}"/$(curl -s ftp://"${FTP_SRV}"/"${FILE}"/latest)