前提
开通sftp账号
安装expect
示例
sh
NEO4J_HOME=/path/to/neo4j # neo4j 安装目录
DUMP_PATH=/data/dump # DUMP本地保存目录
DUMP_FILE=neo4j_$(date +%F).dump #导出文件名称
UPLOAD_DIR=/path/to/stfp/dump/ #上传目录
$NEO4J_HOME/bin/neo4j-admin dump --database=neo4j --to=$DUMP_PATH/$DUMP_FILE
ftp_ip=xx.xx.xx.xx
ftp_port=222
ftp_user=xxxxx
ftp_password=xxxxxxx
/usr/bin/expect <<-EOF
set timeout 100
spawn sftp -P $ftp_port $ftp_user@$ftp_ip
expect {
"*yes/no*" { send "yes
"; exp_continue }
"*assword:" { send "$ftp_password
" }
}
expect "sftp>"
send "lcd ${DUMP_PATH}
"
expect "sftp>"
send "cd ${UPLOAD_DIR}
"
expect "sftp>"
set timeout -1
send "put $DUMP_FILE
"
expect "sftp>"
send "quit
"
expect eof
EOF