Skip to content

Instantly share code, notes, and snippets.

@tanish-kr
Created March 30, 2018 03:45
Show Gist options
  • Save tanish-kr/3165bb6d52b5d52e563ea3eeddaf4d82 to your computer and use it in GitHub Desktop.
Save tanish-kr/3165bb6d52b5d52e563ea3eeddaf4d82 to your computer and use it in GitHub Desktop.
[Ruby]Base64エンコードされたデータをSCPでアップロードする ref: https://qiita.com/kitaro_tn/items/01a498e4e4a2672e991d
$ gem install net-scp
# coding: utf-8
require 'tempfile'
require 'net/scp'
require 'base64'
contents = Base64.encode64("contents")
save_path = "/var/tmp/test.txt"
host = "localhost"
user = "username"
password = ""
Tempfile.create("upload") do |tf|
tf.binmode
tf.write(Base64.decode64(contents))
tf.rewind
file_size = tf.size
Net::SCP.start(host, user,
password: password) do |scp|
scp.upload! tf.path, save_path
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment