Class: Microsandbox::SftpClient

Inherits:
Object
  • Object
show all
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

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

#closenil

Close the SFTP session. Idempotent.

Returns:

  • (nil)


121
122
123
124
# File 'lib/microsandbox/ssh.rb', line 121

def close
  @native.close
  nil
end

#mkdir(path) ⇒ nil

Create a directory.

Returns:

  • (nil)


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.

Returns:

  • (String)

    raw bytes (ASCII-8BIT)



55
56
57
# File 'lib/microsandbox/ssh.rb', line 55

def read(path)
  @native.read(path.to_s)
end

Read a symlink’s target.

Returns:

  • (String)


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).

Returns:

  • (String)


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.

Returns:

  • (String)


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.

Returns:

  • (nil)


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.

Returns:

  • (nil)


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.

Returns:

  • (nil)


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

Create a symlink at link_path pointing to target.

Returns:

  • (nil)


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.

Returns:

  • (nil)


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