Class: Turbotlib::FTP

Inherits:
Net::FTP
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/turbotlib/ftp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host = nil, user = nil, passwd = nil, acct = nil) ⇒ FTP

Returns a new instance of FTP.



72
73
74
75
76
77
78
# File 'lib/turbotlib/ftp.rb', line 72

def initialize(host = nil, user = nil, passwd = nil, acct = nil)
  # Store so we can recreate an FTP client.
  @initialize_args = [host, user, passwd, acct]
  @last_dir = Pathname.new('')
  @last_cmd = nil
  super
end

Instance Attribute Details

#initialize_argsObject (readonly)

Returns the value of attribute initialize_args.



48
49
50
# File 'lib/turbotlib/ftp.rb', line 48

def initialize_args
  @initialize_args
end

#last_cmdObject (readonly)

Returns the value of attribute last_cmd.



48
49
50
# File 'lib/turbotlib/ftp.rb', line 48

def last_cmd
  @last_cmd
end

#last_dirObject (readonly)

Returns the value of attribute last_dir.



48
49
50
# File 'lib/turbotlib/ftp.rb', line 48

def last_dir
  @last_dir
end

#loggerObject

Returns the value of attribute logger.



47
48
49
# File 'lib/turbotlib/ftp.rb', line 47

def logger
  @logger
end

#root_pathObject

Returns the value of attribute root_path.



47
48
49
# File 'lib/turbotlib/ftp.rb', line 47

def root_path
  @root_path
end

Instance Method Details

#chdir(dirname) ⇒ Object



94
95
96
97
98
99
# File 'lib/turbotlib/ftp.rb', line 94

def chdir(dirname)
  info("chdir #{dirname}")
  super
  # Store so we can resume from the directory.
  @last_dir += dirname
end

#download(remotefile) ⇒ File

Downloads a remote file.

Parameters:

  • remotefile (String)

    the name of the remote file

Returns:

  • (File)

    a local file with the remote file’s contents



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

def download(remotefile)
  info("get #{remotefile}")

  path = File.join(root_path, pwd, remotefile)

  if !Turbotlib.in_production? && File.exist?(path)
    File.open(path)
  else
    FileUtils.mkdir_p(File.dirname(path))
    File.open(path, 'w') do |f|
      getbinaryfile(remotefile, f.path)
    end
    File.open(path)
  end
end

#login(*args) ⇒ Object



80
81
82
83
# File 'lib/turbotlib/ftp.rb', line 80

def (*args)
  info('login')
  super
end

#nlst(dir = nil) ⇒ Object



85
86
87
88
89
90
91
92
# File 'lib/turbotlib/ftp.rb', line 85

def nlst(dir = nil)
  if dir
    info("nlst #{dir}")
  else
    info('nlst')
  end
  super
end