Skip to content

Instantly share code, notes, and snippets.

@kenzo0107 kenzo0107/sftpUpload.sh
Last active Feb 28, 2017

Embed
What would you like to do?
#!/bin/sh
# remote serverへ転送するローカルファイル.
LOCAL_FILE="/tmp/*.csv"
# remote server 情報.
REMOTE_IP="**.**.**.**"
REMOTE_USER="user"
REMOTE_PASS="password"
REMOTE_PATH="/path/to/application/"
# sftpでファイルアップロード.
function sftpUpload() {
# /tmp/*.csv を ${REMOTE_PATH} へアップロードする
cat <<EOF > sftp.bat
cd ${REMOTE_PATH}
put ${LOCAL_FILE}
quit
EOF
# sftpでファイルアップロード.
function sftpUpload() {
expect -c "
set timeout 10
spawn sftp -o \"batchmode no\" -b sftp.bat ${REMOTE_USER}@${REMOTE_IP}
expect {
\" Are you sure you want to continue connecting (yes/no)? \" {
send \"yse\r\"
expect \"password:\"
send \"${REMOTE_PASS}\r\"
} \"password:\" {
send \"${REMOTE_PASS}\r\"
}
}
interact
"
}
# sftpによるファイル転送実行.
sftpUpload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.