Bootstrap

ftp脚本 实现非交互模式上传文件

1、Linux ftp脚本 实现非交互模式上传文件



ftpput.sh

-----------------------------------------------------------------------------

#!/bin/sh 


if [ $# -ne 2  ] 

then

    echo "Usage $0  <local_dir/filename> <remote_dir>"

    exit 1

fi


IP=ftp.example.net

FULLNAME=$1

DESTDIR=$2


local_filename=`basename $FULLNAME`

DESTFILE=$DESTDIR/$local_filename


ftp -i -n <<FTPIT

open $IP

user username_xxx password_xxx

bin

passive

hash

cd /

put $FULLNAME $DESTFILE

quit

FTPIT


exit 0

-------------------------------------------------------------------

用法举例:

ftpput.sh backup.tar ftp.example.net/bak


输出类似:

username_xxx@PC-XXX:~/Test$ ftpput.sh backup-20141215.tar.gz private/bak

Passive mode on.

Hash mark printing on (1024 bytes/hash mark).

###############################################


2、Windows下的非交互式脚本


Windows下的ftp命令也支持类似的非交互模式,提前把命令参数定义好,运行bat后,执行一连串的操作。

关键参数:ftp -i -s:some_command.txt


some_command.txt举例如下:

open xxxxxx.net
username_xxx
password_xxx
cd private
mkdir log
mkdir log/some_app
cd private/log/some_app
mkdir 2014-12-16
cd 2014-12-16
bin
hash
mput some_app/*.log
bye


;