Class: SFTPSession
- Inherits:
-
Object
- Object
- SFTPSession
- Defined in:
- lib/guard/autoupload/sftpsession.rb
Instance Method Summary collapse
-
#initialize(host, port, user, password, caller_ref) ⇒ SFTPSession
constructor
A new instance of SFTPSession.
- #mkdir!(dir) ⇒ Object
- #remove!(remote) ⇒ Object
- #rmdir!(dir) ⇒ Object
- #upload!(local, remote) ⇒ Object
Constructor Details
#initialize(host, port, user, password, caller_ref) ⇒ SFTPSession
Returns a new instance of SFTPSession.
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/guard/autoupload/sftpsession.rb', line 4 def initialize(host, port, user, password, caller_ref) @host = host @port = port @user = user @password = password @session = Net::SFTP.start( @host, @user, :password => @password, :port => @port ) @caller = caller_ref end |
Instance Method Details
#mkdir!(dir) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/guard/autoupload/sftpsession.rb', line 22 def mkdir!(dir) begin remote { @session.lstat!(dir) } exists = true rescue Net::SFTP::StatusException exists = false end remote { @session.mkdir!(dir) } unless exists end |
#remove!(remote) ⇒ Object
32 33 34 35 36 |
# File 'lib/guard/autoupload/sftpsession.rb', line 32 def remove!(remote) stat = remote { @session.lstat!(remote) } remote { @session.remove!(remote) } if stat.file? remote { @session.rmdir!(remote) } if stat.directory? end |
#rmdir!(dir) ⇒ Object
38 39 40 |
# File 'lib/guard/autoupload/sftpsession.rb', line 38 def rmdir!(dir) remote { @session.rmdir!(dir) } end |
#upload!(local, remote) ⇒ Object
18 19 20 |
# File 'lib/guard/autoupload/sftpsession.rb', line 18 def upload!(local, remote) remote { @session.upload!(local, remote) } end |