LoginSignup
1
1

More than 5 years have passed since last update.

macから簡単にファイルアップロードを行う

Last updated at Posted at 2016-09-25

macから簡単にscpさせたいなぁ
なんか公開鍵認証の設定とかめんどくさそうだなぁと思いつつ作ったファイルアップロード用シェルです。
前回の記事同様sshpassにより書き換え可能なため、あとでsshpass版も追記予定)

アップロード元rootディレクトリ:/Users/user/Desktop/test/src/

アップロード先rootディレクトリ:/home/pi/Desktop/test/src/
アップロード先ipアドレス:192.168.0.10
アップロード先user名:pi
アップロード先password:raspberry

upload.sh
#!/bin/sh
lRoot=/Users/user/Desktop/test/src/
hRoot=/home/pi/Desktop/test/src/

password='raspberry'
host='192.168.0.10'
id='pi'

expect -c "
set timeout 10
spawn scp -p $lRoot$1 $id@$host:$hRoot
expect \"password:\"
send \"$password\r\"
interact
"

使い方

アップロードしたいファイルが/Users/user/Desktop/test/src/sample.py
アップロード先が/home/pi/Desktop/test/src/の場合は下記の様になる。

. upload.sh sample.py

シェル実行後、/home/pi/Desktop/test/src/sample.pyにアップロードされる。

2016/9/27:追記

  • sshpassを導入した場合
brew install http://git.io/sshpass.rb
auto_login.sh
#!/bin/sh
lRoot=/Users/user/Desktop/test/src/
hRoot=/home/pi/Desktop/test/src/

password='raspberry'
host='192.168.0.10'
id='pi'

sshpass -p $password scp -o StrictHostKeyChecking=no $lRoot$1 $id@$host:$hRoot

1
1
0

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
1
1