Created
March 30, 2018 03:45
-
-
Save tanish-kr/3165bb6d52b5d52e563ea3eeddaf4d82 to your computer and use it in GitHub Desktop.
[Ruby]Base64エンコードされたデータをSCPでアップロードする ref: https://qiita.com/kitaro_tn/items/01a498e4e4a2672e991d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gem install net-scp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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