Module: Ronin::Network::FTP

Included in:
Mixins::FTP, Support
Defined in:
lib/ronin/network/ftp.rb

Overview

Provides helper methods for communicating with FTP servers.

Since:

  • 0.5.0

Constant Summary collapse

DEFAULT_PORT =

Default FTP port

Since:

  • 0.5.0

21
DEFAULT_USER =

Default FTP user

Since:

  • 0.5.0

'anonymous'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_portInteger

Default port used by Ronin::Network::FTP.

Returns:

  • (Integer)

    The default Ronin FTP port.

Since:

  • 0.5.0


44
45
46
# File 'lib/ronin/network/ftp.rb', line 44

def self.default_port
  @default_port ||= DEFAULT_PORT
end

.default_port=(new_port) ⇒ Object

Sets the default port used by Ronin::Network::FTP.

Parameters:

  • new_port (Integer)

    The new default Ronin FTP port.

Since:

  • 0.5.0


56
57
58
# File 'lib/ronin/network/ftp.rb', line 56

def self.default_port=(new_port)
  @default_port = new_port
end

Instance Method Details

#ftp_connect(host, options = {}) {|session| ... } ⇒ Net::FTP

Creates a connection to the FTP server.

Examples:

ftp_connect('www.example.com', :user => 'joe', :password => 'secret')

Parameters:

  • host (String)

    The host to connect to.

  • options (Hash) (defaults to: {})

    Additional options.

Options Hash (options):

  • :port (Integer) — default: FTP.default_port

    The port to connect to.

  • :user (String) — default: DEFAULT_USER

    The user to authenticate with.

  • :password (String)

    The password to authenticate with.

  • :account (String)

    The FTP account information to send via the ACCT command.

  • :passive (Boolean) — default: true

    Specifies whether the FTP session should use passive mode.

Yields:

  • (session)

    If a block is given, it will be passed an FTP session object.

Yield Parameters:

  • session (Net::FTP)

    The FTP session.

Returns:

  • (Net::FTP)

    The FTP session.

Since:

  • 0.5.0


98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/ronin/network/ftp.rb', line 98

def ftp_connect(host,options={})
  host     = host.to_s
  port     = (options[:port] || FTP.default_port)
  user     = (options[:user] || DEFAULT_USER)
  password = options[:password]
  acct     = options[:account]

  session = Net::FTP.new
  session.connect(host,port)
  session.(user,password,acct)
  session.passive = options.fetch(:passive,true)

  yield session if block_given?
  return session
end

#ftp_session(host, options = {}) {|session| ... } ⇒ Object

Starts a session with the FTP server.

Examples:

ftp_session('www.example.com', :user => 'joe') do |ftp|
  # ...
end

Parameters:

  • host (String)

    The host to connect to.

  • options (Hash) (defaults to: {})

    Additional options.

Yields:

  • (session)

    If a block is given, it will be passed an FTP session object. After the block has returned, the session will be closed.

Yield Parameters:

  • session (Net::FTP)

    The FTP session.

See Also:

Since:

  • 0.5.0


139
140
141
142
143
144
145
146
# File 'lib/ronin/network/ftp.rb', line 139

def ftp_session(host,options={})
  ftp = ftp_connect(host,options)

  yield ftp if block_given?

  ftp.close
  return nil
end