Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Using Net::FTP need to get latest file from the directory ?

by gube (Parson)
on Mar 10, 2009 at 22:05 UTC ( #749745=perlquestion: print w/ replies, xml ) Need Help??
gube has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

I am using Net::FTP module to get a file from ftp in one of my directory. I want to get the latest file from directory. Is there any option like we have $ftp->ls() ?

Thanks

Comment on Using Net::FTP need to get latest file from the directory ?
Re: Using Net::FTP need to get latest file from the directory ?
by Lawliet (Curate) on Mar 10, 2009 at 22:19 UTC

    Huh? Are you asking if there are methods like ls([ DIR ]) and dir([ DIR]) (both found in the documentation for Net::FTP). Or are you asking if there is a method that specifically gets the "latest" file? If the latter option, the question "what do you mean by latest?" comes to mind. Assuming you mean file that was most recently changed, you can use mdtm( FILE ) to find the modification time for the file in question.

    That being said, care to elaborate? Will regular Perl file checks not work?

    And you didn't even know bears could type.

Re: Using Net::FTP need to get latest file from the directory ?
by gube (Parson) on Mar 11, 2009 at 03:10 UTC
    Thanks for your reply. Yes i want the latest modification file. I meant ls -rt in linux will show the first file as latest file i need the same to be collected from FTP.

    Gubs

      You can use the ls or dir method to get a list of the files in the directory, then use the mdtm method on each file to get its modification time and select the file with the latest modifiction time.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://749745]
Approved by ELISHEVA
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2014-12-29 04:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (184 votes), past polls