Class: Microsandbox::SftpClient
- Inherits:
-
Object
- Object
- Microsandbox::SftpClient
- Defined in:
- lib/microsandbox/ssh.rb
Overview
A high-level SFTP session over an SshClient, from Microsandbox::SshClient#sftp. All paths are guest paths. Mirrors the ‘SftpClient` of the official SDKs.
Instance Method Summary collapse
-
#close ⇒ nil
Close the SFTP session.
-
#initialize(native) ⇒ SftpClient
constructor
A new instance of SftpClient.
-
#mkdir(path) ⇒ nil
Create a directory.
-
#read(path) ⇒ String
Read a file’s full contents.
-
#read_link(path) ⇒ String
Read a symlink’s target.
-
#read_text(path) ⇒ String
Read a file and decode it as UTF-8 (lenient).
-
#real_path(path) ⇒ String
Resolve a path to its canonical absolute form.
-
#remove_dir(path) ⇒ nil
Remove an empty directory.
-
#remove_file(path) ⇒ nil
Remove a file.
-
#rename(old_path, new_path) ⇒ nil
Rename (move) a file or directory.
-
#symlink(target, link_path) ⇒ nil
Create a symlink at
link_pathpointing totarget. -
#write(path, data) ⇒ nil
Write a file, creating or truncating it.
Constructor Details
#initialize(native) ⇒ SftpClient
Returns a new instance of SftpClient.
49 50 51 |
# File 'lib/microsandbox/ssh.rb', line 49 def initialize(native) @native = native end |
Instance Method Details
#close ⇒ nil
Close the SFTP session. Idempotent.
121 122 123 124 |
# File 'lib/microsandbox/ssh.rb', line 121 def close @native.close nil end |
#mkdir(path) ⇒ nil
Create a directory.
74 75 76 77 |
# File 'lib/microsandbox/ssh.rb', line 74 def mkdir(path) @native.mkdir(path.to_s) nil end |
#read(path) ⇒ String
Read a file’s full contents.
55 56 57 |
# File 'lib/microsandbox/ssh.rb', line 55 def read(path) @native.read(path.to_s) end |
#read_link(path) ⇒ String
Read a symlink’s target.
115 116 117 |
# File 'lib/microsandbox/ssh.rb', line 115 def read_link(path) @native.read_link(path.to_s) end |
#read_text(path) ⇒ String
Read a file and decode it as UTF-8 (lenient).
61 62 63 |
# File 'lib/microsandbox/ssh.rb', line 61 def read_text(path) read(path).force_encoding(Encoding::UTF_8) end |
#real_path(path) ⇒ String
Resolve a path to its canonical absolute form.
109 110 111 |
# File 'lib/microsandbox/ssh.rb', line 109 def real_path(path) @native.real_path(path.to_s) end |
#remove_dir(path) ⇒ nil
Remove an empty directory.
88 89 90 91 |
# File 'lib/microsandbox/ssh.rb', line 88 def remove_dir(path) @native.remove_dir(path.to_s) nil end |
#remove_file(path) ⇒ nil
Remove a file.
81 82 83 84 |
# File 'lib/microsandbox/ssh.rb', line 81 def remove_file(path) @native.remove_file(path.to_s) nil end |
#rename(old_path, new_path) ⇒ nil
Rename (move) a file or directory.
95 96 97 98 |
# File 'lib/microsandbox/ssh.rb', line 95 def rename(old_path, new_path) @native.rename(old_path.to_s, new_path.to_s) nil end |
#symlink(target, link_path) ⇒ nil
Create a symlink at link_path pointing to target.
102 103 104 105 |
# File 'lib/microsandbox/ssh.rb', line 102 def symlink(target, link_path) @native.symlink(target.to_s, link_path.to_s) nil end |
#write(path, data) ⇒ nil
Write a file, creating or truncating it.
67 68 69 70 |
# File 'lib/microsandbox/ssh.rb', line 67 def write(path, data) @native.write(path.to_s, data.to_s) nil end |