Type:
Class
Constants:
MDTM_REGEXP : /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/

This class implements the File Transfer Protocol. If you have used a command-line FTP program, and are familiar with the commands, you will be able to use this class easily. Some extra features are included to take advantage of Ruby's style and strengths.

Example

1
require 'net/ftp'

Example 1

1
2
3
4
5
6
ftp = Net::FTP.new('example.com')
ftp.login
files = ftp.chdir('pub/lang/ruby/contrib')
files = ftp.list('n*')
ftp.getbinaryfile('nif.rb-0.91.gz', 'nif.gz', 1024)
ftp.close

Example 2

1
2
3
4
5
6
Net::FTP.open('example.com') do |ftp|
  ftp.login
  files = ftp.chdir('pub/lang/ruby/contrib')
  files = ftp.list('n*')
  ftp.getbinaryfile('nif.rb-0.91.gz', 'nif.gz', 1024)
end

Major Methods

The following are the methods most likely to be useful to users:

abort
  • References/Ruby on Rails/Ruby/Classes/Net/Net::FTP

abort() Instance Public methods Aborts the previous command (ABOR command).

2025-01-10 15:47:30
rename
  • References/Ruby on Rails/Ruby/Classes/Net/Net::FTP

rename(fromname, toname) Instance Public methods Renames a file on the server

2025-01-10 15:47:30
storbinary
  • References/Ruby on Rails/Ruby/Classes/Net/Net::FTP

storbinary(cmd, file, blocksize, rest_offset = nil) Instance Public methods Puts

2025-01-10 15:47:30
mtime
  • References/Ruby on Rails/Ruby/Classes/Net/Net::FTP

mtime(filename, local = false) Instance Public methods Returns the last modification

2025-01-10 15:47:30
connect
  • References/Ruby on Rails/Ruby/Classes/Net/Net::FTP

connect(host, port = FTP_PORT) Instance Public methods Establishes an

2025-01-10 15:47:30
binary=
  • References/Ruby on Rails/Ruby/Classes/Net/Net::FTP

binary=(newmode) Instance Public methods A setter to toggle transfers in binary

2025-01-10 15:47:30
getbinaryfile
  • References/Ruby on Rails/Ruby/Classes/Net/Net::FTP

getbinaryfile(remotefile, localfile = File.basename(remotefile), blocksize = DEFAULT_BLOCKSIZE) Instance Public methods

2025-01-10 15:47:30
sendcmd
  • References/Ruby on Rails/Ruby/Classes/Net/Net::FTP

sendcmd(cmd) Instance Public methods Sends a command and returns the response

2025-01-10 15:47:30
delete
  • References/Ruby on Rails/Ruby/Classes/Net/Net::FTP

delete(filename) Instance Public methods Deletes a file on the server.

2025-01-10 15:47:30
closed?
  • References/Ruby on Rails/Ruby/Classes/Net/Net::FTP

closed?() Instance Public methods Returns true iff the connection

2025-01-10 15:47:30