Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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%3Apassword@ftpserver/dir/*

Regards, Ram.

share|improve this question

migrated from serverfault.com Oct 21 '09 at 11:10

This question came from our site for system and network administrators.

4  
why don't you give us a little bit less information to work with? –  hop Oct 20 '09 at 16:25

4 Answers 4

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.

share|improve this answer
    
using wget I am able to get all files issue is if I have that file already then it is coming and storeing as file_name.1 I want to download the files which are not available there. –  Ram Oct 20 '09 at 23:19

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%3Apassword@ftpserver/dir/*

share|improve this answer

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).

share|improve this answer
    
Hi The file is like file-name_YYYYMMDD.sql.gz where YYYY - year, MM - month, DD -date I cant specify the exact file name –  Ram Oct 20 '09 at 17:18
    
Seems like a database backup / schema script –  Sathya Oct 21 '09 at 12:10

My Solution is this:

curl 'ftp://server.de/dir/'$(curl 'ftp://server.de/dir/' 2>/dev/null | tail -1 | awk '{print $(NF)}')
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.