Class: Ghaki::NetSSH::FTP
- Inherits:
-
Net::SFTP
- Object
- Net::SFTP
- Ghaki::NetSSH::FTP
- Extended by:
- Forwardable
- Defined in:
- lib/ghaki/net_ssh/ftp.rb
Instance Attribute Summary collapse
-
#raw_ftp ⇒ Object
Returns the value of attribute raw_ftp.
-
#shell ⇒ Object
Returns the value of attribute shell.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #download!(rem_file, loc_file) ⇒ Object
-
#initialize(ssh) ⇒ FTP
constructor
A new instance of FTP.
- #remove!(fname) ⇒ Object
- #upload!(loc_file, rem_file) ⇒ Object
Constructor Details
#initialize(ssh) ⇒ FTP
Returns a new instance of FTP.
38 39 40 41 42 |
# File 'lib/ghaki/net_ssh/ftp.rb', line 38 def initialize ssh @shell = ssh @raw_ftp = @shell.raw_ssh.sftp super(@raw_ftp) end |
Instance Attribute Details
#raw_ftp ⇒ Object
Returns the value of attribute raw_ftp.
14 15 16 |
# File 'lib/ghaki/net_ssh/ftp.rb', line 14 def raw_ftp @raw_ftp end |
#shell ⇒ Object
Returns the value of attribute shell.
14 15 16 |
# File 'lib/ghaki/net_ssh/ftp.rb', line 14 def shell @shell end |
Class Method Details
.start(*args) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ghaki/net_ssh/ftp.rb', line 20 def self.start *args ssh_gak = Ghaki::NetSSH::Shell.start( *args ) ftp_gak = Ghaki::NetSSH::FTP.new( ssh_gak ) if block_given? begin yield ftp_gak ensure ssh_gak.close end else return ftp_gak end end |
Instance Method Details
#close ⇒ Object
34 35 36 |
# File 'lib/ghaki/net_ssh/ftp.rb', line 34 def close @shell.close end |
#download!(rem_file, loc_file) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/ghaki/net_ssh/ftp.rb', line 64 def download! rem_file, loc_file log_command! 'SFTP', "download #{rem_file}, #{loc_file}" File.with_named_temp loc_file do |tmp_file| @raw_ftp.download! rem_file, tmp_file end end |
#remove!(fname) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/ghaki/net_ssh/ftp.rb', line 44 def remove! fname begin log_command! 'SFTP', "remove #{fname}" @raw_ftp.remove! fname rescue ::Net::SFTP::StatusException raise unless $!. =~ %r{ \b no \s such \s file \b }oix end end |
#upload!(loc_file, rem_file) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ghaki/net_ssh/ftp.rb', line 53 def upload! loc_file, rem_file tmp_file = ::File.join( ::File.dirname(rem_file), '_tmp_' + $$.to_s + '.' + ::File.basename(rem_file) ) log_command! 'SFTP', "upload #{loc_file}, #{tmp_file}" @raw_ftp.upload! loc_file, tmp_file log_command! 'SFTP', "rename #{tmp_file}, #{rem_file}" @raw_ftp.rename! tmp_file, rem_file ensure self.remove! tmp_file end |