Connecting to an FTP server with net/ftp using an FTP URL is a simple operation: : FTP Client « Network « Ruby






Connecting to an FTP server with net/ftp using an FTP URL is a simple operation:

require 'net/ftp'
require 'uri'

uri = URI.parse('ftp://ftp.ruby-lang.org/')

Net::FTP.open(uri.host) do |ftp|
  ftp.login 'anonymous', 'me@privacy.net'
  ftp.passive = true
  ftp.list(uri.path) { |path| puts path }
end

 








Related examples in the same category

1.File Transfers with FTP
2.Net::FTP provides a login method that you can use against a Net::FTP object, like so:
3.if a username and password are required, use this code:
4.use the chdir method:
5.change to any directory in the remote filesystem:
6.Ftp mkdir
7.delete and rename files
8.Set the mode to passive
9.Downloading Files
10.prints a string to the screen whenever another 100 kilobytes of the file have been downloaded.
11.Uploading Files
12.keep the user informed of the progress of the upload.
13.Create a temporary file with Tempfile and upload from that