Skip to content
On this page

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class · Ruby 3.0

Net::FTP

include MonitorMixin include OpenSSL include OpenSSL::SSL 50 instance methods 4 class methods

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

Example
require 'net/ftp'

Example 1

Example
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

Example
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:

Class methods 4

Instance methods 50

Constants
No documentation available
No documentation available
No documentation available
No documentation available
No documentation available
No documentation available
Attributes
Read

When true, transfers are performed in binary mode. Default: true.

Read & Write

When true, all traffic to and from the server is written to +$stdout+. Default: false.

Read

The server’s last response code.

The server’s last response.

The server’s last response code.

Read & Write

Number of seconds to wait for the connection to open. Any number may be used, including Floats for fractional seconds. If the FTP object cannot open a connection in this many seconds, it raises a Net::OpenTimeout exception. The default value is nil.

Read & Write

When true, the connection is in passive mode. Default: true.

Number of seconds to wait for one block to be read (via one read(2) call). Any number may be used, including Floats for fractional seconds. If the FTP object cannot read data in this many seconds, it raises a Timeout::Error exception. The default value is 60 seconds.

Read & Write

Sets or retrieves the resume status, which decides whether incomplete transfers are resumed or restarted. Default: false.

Read & Write

Number of seconds to wait for the TLS handshake. Any number may be used, including Floats for fractional seconds. If the FTP object cannot complete the TLS handshake in this many seconds, it raises a Net::OpenTimeout exception. The default value is nil. If ssl_handshake_timeout is nil, open_timeout is used instead.

Read & Write

When true, use the IP address in PASV responses. Otherwise, it uses the same IP address for the control connection. Default: false.

Read

The server’s welcome message.