Class Net::FTP
In: lib/net/ftp-netrc.rb
Parent: Object

Methods

login  

External Aliases

connect -> orig_connect
login -> orig_login

Public Instance methods

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 user@host 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.

[Source]

# File lib/net/ftp-netrc.rb, line 57
    def login(user = "anonymous", passwd = nil, acct = nil)
      if user.nil?
        rc = Net::Netrc.locate(@host)
        if rc
          user = rc.login
          passwd = rc.password
          acct = rc.account
        else
          user = ''
          passwd = ''
        end
      end
      orig_login(user, passwd, acct)
    end

[Validate]