Class: FtpMultipartDownload::Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/ftp_multipart_download/downloader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host = nil, user_or_options = {}, passwd = nil, acct = nil) ⇒ Downloader

see Net::FTP#initialize

Parameters:

  • host (String) (defaults to: nil)

    Host name.

  • user_or_options (Hash, String) (defaults to: {})

    username or option as Hash.

  • passwd (String) (defaults to: nil)

    password

  • Account (String)

    information for ACCT.



12
13
14
# File 'lib/ftp_multipart_download/downloader.rb', line 12

def initialize(host = nil, user_or_options = {}, passwd = nil, acct = nil)
  @argv = [host, user_or_options, passwd, acct]
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



3
4
5
# File 'lib/ftp_multipart_download/downloader.rb', line 3

def argv
  @argv
end

Instance Method Details

#download(concurrent, remotefile, localfile = File.basename(remotefile), blocksize = DEFAULT_BLOCKSIZE) ⇒ Object

concurrent multipart downloading.

Parameters:

  • concurrent (Integer)

    number of concurrent download sessions.

  • remotefile (String)

    remote file path.

  • localfile (String) (defaults to: File.basename(remotefile))

    local file path.

  • blocksize (Integer) (defaults to: DEFAULT_BLOCKSIZE)

    block size.

Raises:



24
25
26
27
28
29
30
31
# File 'lib/ftp_multipart_download/downloader.rb', line 24

def download(concurrent, remotefile, localfile = File.basename(remotefile), blocksize = DEFAULT_BLOCKSIZE)
  connection_pool = ConnectionPool.new(concurrent, *argv)
  if connection_pool.count == 0
    raise ConnectionError.new('Could not establish any connection.', errors: connection_pool.errors)
  end

  Scheduler.new(connection_pool).schedule(remotefile, localfile, blocksize)
end