Class: Net::FTP

Inherits:
Object
  • Object
show all
Defined in:
lib/net/ftp-netrc.rb

Instance Method Summary collapse

Instance Method Details

#connect(host, port = FTP_PORT) ⇒ Object

cache host name for later use by login


31
32
33
34
# File 'lib/net/ftp-netrc.rb', line 31

def connect(host, port = FTP_PORT) # :nodoc:
  @host = host
  orig_connect(host, port)
end

#login(user = "anonymous", passwd = nil, acct = nil) ⇒ Object

Logs in to the remote host. The session must have been previously connected.

If user is nil, Net::Netrc#locate is used to lookup login information based on the host name supplied when the connection was established.

If user is the string “anonymous” and the password is nil, a password of [email protected] is synthesized. If the acct parameter is not nil, an FTP ACCT command is sent following the successful login. Raises an exception on error (typically Net::FTPPermError).

Example:

require 'net/ftp-netrc'     # (brings in net/ftp and net/netrc)

ftp = Net::FTP.new('myhost')
ftp.login(nil)
ftp.last_response
=> 230 User myuser logged in.

57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/net/ftp-netrc.rb', line 57

def (user = "anonymous", passwd = nil, acct = nil)
  if user.nil?
    rc = Net::Netrc.locate(@host)
    if rc
      user = rc.
      passwd = rc.password
      acct = rc.
    else
      user = ''
      passwd = ''
    end
  end
  (user, passwd, acct)
end

#orig_connectObject

:nodoc:


27
# File 'lib/net/ftp-netrc.rb', line 27

alias_method :orig_connect, :connect

#orig_loginObject

:nodoc:


28
# File 'lib/net/ftp-netrc.rb', line 28

alias_method :orig_login, :login