Module: Ronin::Support::Network::FTP::Mixin

Included in:
Mixin
Defined in:
lib/ronin/support/network/ftp/mixin.rb

Overview

Provides helper methods for communicating with FTP servers.

Constant Summary collapse

DEFAULT_PORT =

Default FTP port

21
DEFAULT_USER =

Default FTP user

'anonymous'

Instance Method Summary collapse

Instance Method Details

#ftp_connect(host, port: DEFAULT_PORT, user: DEFAULT_USER, password: nil, account: nil, passive: true) {|ftp| ... } ⇒ Net::FTP?

Creates a connection to the FTP server.

Examples:

ftp_connect('www.example.com', user: 'joe', password: 'secret')
ftp_connect('www.example.com', user: 'joe', password: 'secret') do |ftp|
  # ...
end

Parameters:

  • host (String)

    The host to connect to.

  • port (Integer) (defaults to: DEFAULT_PORT)

    The port to connect to.

  • user (String) (defaults to: DEFAULT_USER)

    The user to authenticate with.

  • password (String) (defaults to: nil)

    The password to authenticate with.

  • account (String) (defaults to: nil)

    The FTP account information to send via the ACCT command.

  • passive (Boolean) (defaults to: true)

    Specifies whether the FTP session should use passive mode.

Yields:

  • (ftp)

    If a block is given, it will be passed an FTP session object. Once the block returns, the FTP session will be closed.

Yield Parameters:

  • ftp (Net::FTP)

    The FTP session.

Returns:

  • (Net::FTP, nil)

    The FTP session. If a block is given, then nil will be returned.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/ronin/support/network/ftp/mixin.rb', line 83

def ftp_connect(host, port:     DEFAULT_PORT,
                      user:     DEFAULT_USER,
                      password: nil,
                      account:  nil,
                      passive:  true)
  host = DNS::IDN.to_ascii(host)
  ftp  = Net::FTP.new

  ftp.connect(host,port)
  ftp.(user,password,)
  ftp.passive = passive

  if block_given?
    yield ftp
    ftp.close
  else
    return ftp
  end
end