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 (lossy — invalid byte sequences are replaced with U+FFFD).
-
#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.
50 51 52 |
# File 'lib/microsandbox/ssh.rb', line 50 def initialize(native) @native = native end |
Instance Method Details
#close ⇒ nil
Close the SFTP session. Idempotent.
126 127 128 129 |
# File 'lib/microsandbox/ssh.rb', line 126 def close @native.close nil end |
#mkdir(path) ⇒ nil
Create a directory.
79 80 81 82 |
# File 'lib/microsandbox/ssh.rb', line 79 def mkdir(path) @native.mkdir(path.to_s) nil end |
#read(path) ⇒ String
Read a file’s full contents.
56 57 58 |
# File 'lib/microsandbox/ssh.rb', line 56 def read(path) @native.read(path.to_s) end |
#read_link(path) ⇒ String
Read a symlink’s target.
120 121 122 |
# File 'lib/microsandbox/ssh.rb', line 120 def read_link(path) @native.read_link(path.to_s) end |
#read_text(path) ⇒ String
Read a file and decode it as UTF-8 (lossy — invalid byte sequences are replaced with U+FFFD).
63 64 65 |
# File 'lib/microsandbox/ssh.rb', line 63 def read_text(path) read(path).force_encoding(Encoding::UTF_8).scrub end |
#real_path(path) ⇒ String
Resolve a path to its canonical absolute form.
114 115 116 |
# File 'lib/microsandbox/ssh.rb', line 114 def real_path(path) @native.real_path(path.to_s) end |
#remove_dir(path) ⇒ nil
Remove an empty directory.
93 94 95 96 |
# File 'lib/microsandbox/ssh.rb', line 93 def remove_dir(path) @native.remove_dir(path.to_s) nil end |
#remove_file(path) ⇒ nil
Remove a file.
86 87 88 89 |
# File 'lib/microsandbox/ssh.rb', line 86 def remove_file(path) @native.remove_file(path.to_s) nil end |
#rename(old_path, new_path) ⇒ nil
Rename (move) a file or directory.
100 101 102 103 |
# File 'lib/microsandbox/ssh.rb', line 100 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.
107 108 109 110 |
# File 'lib/microsandbox/ssh.rb', line 107 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.
71 72 73 74 75 |
# File 'lib/microsandbox/ssh.rb', line 71 def write(path, data) bytes = Microsandbox.coerce_write_bytes(data) @native.write(path.to_s, bytes) nil end |