Kanrisuru

upload

Upload a file to a remote server in ruby.
linux manual

Basic Usage

require 'kanrisuru'
host = Kanrisuru::Remote::Host.new(host: 'centos-host', username: 'centos', keys: ['~/.ssh/id_rsa'])

result = host.upload("~/projects/kanrisuru/certs", '/etc/nginx/ssl/certs', recursive: true)
result.success?
true

result.path
'/etc/nginx/ssl/certs'

This command might need escalated privlidges to access certain files that have file permissions set for root access.

Parameters

Field Type Description
local_path string
Required path on local machine to upload a file / directory.
remote_path string
Path on remote machine to upload file or directory to.
recursive boolean
Should upload a remote directory and recursively upload all of it's subdirectories

Result

Returns a single FileStat struct.

FileStat Fields

Field Type Description
mode Kanrisuru::Mode The mode bits set for the file / directory.
blocks integer The number of blocks allocated for the file.
device string The major and minor device number combined into one value (in hex and decimal) of the device on which the file resides.
file_type string What's the file type, ie: directory, file, block_device, char_device, symlink
gid integer The group id in which the file belongs to.
group string The group name in which the file belongs to.
links integer Number of hard links pointing to the underlying inode.
inode integer Unique inode value assigned to the file
path string Where is the file located at
fsize integer Size of the file (in bytes)
uid integer The user id that owns the file
user string The user that owns the file
last_access DateTime When was the last time the file was accessed.
last_modified DateTime When was the last time the file was updated.
last_change DateTime When was the last time the file was changed.

Return Example

host.upload('~/files', '/home/ubuntu/files', recursive: true).data
#<Struct:Kanrisuru::Core::Stat::FileStat:0x00000668
  attr_reader :size = 4096,
  blocks = 8,
  device = "fc01",
  file_type = "directory",
  gid = 1000,
  group = "ubuntu",
  inode = 1552072,
  last_access = #<DateTime: 2022-01-08T11:15:50-06:00 ((2459588j,62150s,911827766n),-21600s,2299161j)>,
  last_changed = #<DateTime: 2022-01-08T11:15:50-06:00 ((2459588j,62150s,991826940n),-21600s,2299161j)>,
  last_modified = #<DateTime: 2022-01-08T11:15:50-06:00 ((2459588j,62150s,991826940n),-21600s,2299161j)>,
  links = 2,
  mode = #<Kanrisuru::Mode:0x800 @numeric=775 @symbolic=drwxrwxr-x>,
  path = "/home/ubuntu/files",
  uid = 1000,
  user = "ubuntu"
>

Exit Status

Code Description
0 Success
1 Failure

Tested On

  • Ubuntu, Debian, Centos, Fedora, Redhat, OpenSuse, SLES