#!/bin/bash
#set -x
# FTP服务器信息
FTP_HOST="ftp.deepvision-tech.com"
FTP_USERNAME="huangbinbin"
FTP_PASSWORD="xxxxx."
# 远程目录和文件
REMOTE_DIRECTORY=$1
LOCAL_FILE=$2
ftp_command="ftp -n $FTP_HOST"
check_directory="cd $REMOTE_DIRECTORY"
create_directory="mkdir $REMOTE_DIRECTORY"
upload_file="put $LOCAL_FILE"
expect -c "
spawn $ftp_command
send \"user $FTP_USERNAME\r\"
expect \"Password\"
send \"$FTP_PASSWORD\r\"
expect \"ftp>\"
send \"$check_directory\r\"
expect {
\"Directory successfully changed\" {
send \"$upload_file\r\"
expect \"ftp>\"
}
\"Failed to change directory.\" {
send \"$create_directory\r\"
expect \"ftp>\"
send \"$check_directory\r\"
expect {
\"Directory successfully changed\" {
send \"$upload_file\r\"
expect \"ftp>\"
}
\"Failed to change directory.\" {
exit 1
}
default {
puts \"timeout .\"
exit 1
}
}
}
default {
puts \"timeout .\"
exit 1
}
}
expect eof
"
#interact
标签:ftp,file,FTP,except,send,expect,和子,linux,directory
From: https://www.cnblogs.com/nocanstillbb/p/18034421