# FTP File download

**URL:** <https://www.ruby-forum.com/t/ftp-file-download/122284>\
**Category:** Ruby\
**Created:** [December 6, 2007, 6:29am UTC](https://www.ruby-forum.com/t/ftp-file-download/122284 "2007-12-06T06:29:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brianspaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/82dd89/32.png) [@brianspaid](https://www.ruby-forum.com/u/brianspaid)\
**Post date:** [December 6, 2007, 6:29am UTC](https://www.ruby-forum.com/t/ftp-file-download/122284/1 "2007-12-06T06:29:23Z")

</div>

Hello,

I am a Ruby N.

I need to login to a ftp server and download the newest file on the  
server. I know the basics of Net::FTP but I can’t figure out how to  
download the newest file based on its time stamp.

Any Ideas

Thanks

---

<div class="post-metadata">

**Author:** ![brianspaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/82dd89/32.png) [@brianspaid](https://www.ruby-forum.com/u/brianspaid)\
**Post date:** [December 6, 2007, 12:29pm UTC](https://www.ruby-forum.com/t/ftp-file-download/122284/2 "2007-12-06T12:29:30Z")

</div>

On Dec 6, 2007 6:29 AM, Brian S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello,
> 
> I am a Ruby N.
> 
> I need to login to a ftp server and download the newest file on the  
> server. I know the basics of Net::FTP but I can’t figure out how to  
> download the newest file based on its time stamp.

FTP#list gives you list of files, possibly with timestamps, and  
FTP#mtime gives you last modification time of a particular file.

RTFRDoc 😉 (e.g. [RDoc Documentation](http://ruby-doc.org/core/))

---

<div class="post-metadata">

**Author:** ![brianspaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/82dd89/32.png) [@brianspaid](https://www.ruby-forum.com/u/brianspaid)\
**Post date:** [December 6, 2007, 6:42pm UTC](https://www.ruby-forum.com/t/ftp-file-download/122284/3 "2007-12-06T18:42:12Z")

</div>

On Dec 6, 2007 5:27 AM, Jano S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> FTP#mtime gives you last modification time of a particular file.
> 
> RTFRDoc 😉 (e.g. [RDoc Documentation](http://ruby-doc.org/core/))

Thanks for the link to the docs. Here’s the one for NET::FTP:

[http://ruby-doc.org/core/classes/Net/FTP.html](http://ruby-doc.org/core/classes/Net/FTP.html)

Unfortunately, I can’t get the example to work for me. Specifically,  
this worked:

$ ruby -le ‘require “net/ftp” ; print “hello”’

but this does not, i.e. it just sits there:

$ ruby -le ‘require “net/ftp” ; ftp = Net::FTP.new(“ftp.netlab.co.jp”)  
; print “hello”’

So I changed to an ftp server that I know works, i.e. I can connect to  
it via firefox:

$ ruby -le ‘require “net/ftp” ; ftp =  
Net::FTP.new(“[ftp.ncbi.nlm.nih.gov](http://ftp.ncbi.nlm.nih.gov)”) ; print “hello”’

Still no dice. It’s possible that this is because I’m behind a  
firewall? ftp\_proxy is set  
to something like “[http://proxy.foobar.com:12345](http://proxy.foobar.com:12345)” and I’ve issued an  
‘export SOCKS\_SERVER=$ftp\_proxy’, but ruby still doesn’t work for me.

FYI:

$ ( set -x ; ruby -v ; cat /etc/issue.net )

- ruby -v  
ruby 1.8.5 (2006-08-25) [i486-linux]
- cat /etc/issue.net  
Ubuntu 7.04

Any pointers in the right direction appreciated.

Regards,

- Robert
