Class: Etna::Filesystem::SftpFilesystem

Inherits:
Etna::Filesystem show all
Defined in:
lib/etna/filesystem.rb

Instance Method Summary collapse

Methods inherited from Etna::Filesystem

#mkdir_p, #mv, #rm_rf, #tmpdir, #with_writeable

Constructor Details

#initialize(host:, username:, password: nil, port: 22, **args) ⇒ SftpFilesystem

Returns a new instance of SftpFilesystem.



380
381
382
383
384
385
# File 'lib/etna/filesystem.rb', line 380

def initialize(host:, username:, password: nil, port: 22, **args)
  @username = username
  @password = password
  @host = host
  @port = port
end

Instance Method Details

#exist?(src) ⇒ Boolean

Returns:

  • (Boolean)


408
409
410
411
412
413
414
415
# File 'lib/etna/filesystem.rb', line 408

def exist?(src)
  begin
    sftp.file.open(src)
  rescue Net::SFTP::StatusException
    return false
  end
  return true
end

#ls(dir) ⇒ Object



404
405
406
# File 'lib/etna/filesystem.rb', line 404

def ls(dir)
  sftp.dir.entries(dir)
end

#sftpObject



391
392
393
394
395
396
397
398
# File 'lib/etna/filesystem.rb', line 391

def sftp
  @sftp ||= begin
    conn = Net::SFTP::Session.new(ssh)
    conn.loop { conn.opening? }

    conn
  end
end

#sshObject



387
388
389
# File 'lib/etna/filesystem.rb', line 387

def ssh
  @ssh ||= Net::SSH.start(@host, @username, password: @password)
end

#stat(src) ⇒ Object



417
418
419
# File 'lib/etna/filesystem.rb', line 417

def stat(src)
  sftp.file.open(src).stat
end

#with_readable(src, opts = 'r', &block) ⇒ Object



400
401
402
# File 'lib/etna/filesystem.rb', line 400

def with_readable(src, opts = 'r', &block)
  sftp.file.open(src, opts, &block)
end