Class: Higan::Session
- Inherits:
-
Object
- Object
- Higan::Session
- Defined in:
- lib/higan/session.rb
Instance Attribute Summary collapse
-
#ftp ⇒ Object
Returns the value of attribute ftp.
Instance Method Summary collapse
-
#initialize(host:, user:, password:, mode: nil, **rest) {|ftp, _self| ... } ⇒ Session
constructor
A new instance of Session.
- #mkdir_p(path) ⇒ Object
Constructor Details
#initialize(host:, user:, password:, mode: nil, **rest) {|ftp, _self| ... } ⇒ Session
Returns a new instance of Session.
8 9 10 11 12 13 14 15 |
# File 'lib/higan/session.rb', line 8 def initialize(host:, user:, password:, mode: nil, **rest) self.ftp = Net::FTP.new ftp.connect(host) ftp.login(user, password) ftp.binary = mode.to_sym == :binary yield(ftp, self) if block_given? ftp.close end |
Instance Attribute Details
#ftp ⇒ Object
Returns the value of attribute ftp.
6 7 8 |
# File 'lib/higan/session.rb', line 6 def ftp @ftp end |
Instance Method Details
#mkdir_p(path) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/higan/session.rb', line 17 def mkdir_p(path) dirs = path ftp.chdir('/') dirs.split('/').each do |dir_name| next if dir_name.blank? file_name_list = ftp.ls.map { |line| line.match(/([^\s]+$)/)[1] } unless file_name_list.include? dir_name ftp.mkdir(dir_name) end ftp.chdir(dir_name) end ftp.chdir('/') end |