LoginSignup
16
17

More than 5 years have passed since last update.

net/sftpを用いてsftpを利用する方法を簡単にまとめる。

接続

net/sshに依存している

パスワードを用いて接続する方法


option = {
  password: 'password',
  port: 22,
}

Net::SFTP.start('host', 'username', option) do |sftp|
end

秘密鍵を用いる方法

option = {
  keys: '/path/to/your/identity_key',
  passphrase: 'your-identity-key-pass-phrase',
  port: 22,
}

Net::SFTP.start('host', 'username', option) do |sftp|
end

ファイルのput/get

put


Net::SFTP.start('host', 'username', option) do |sftp|
  sftp.upload!('/path/to/local_file', '/path/to/remote_file')
end

get


Net::SFTP.start('host', 'username', option) do |sftp|
  sftp.download!("/path/to/remote_file", "/path/to/local_file")
end

16
17
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
17