〖Linux〗上传单个文件到FTP的Shell命令行(函数)

 1 #!/bin/bash - 
 2 #===============================================================================
 3 #
 4 #          FILE: ftp_put_file.sh
 5 # 
 6 #         USAGE: ./ftp_put_file.sh 
 7 # 
 8 #   DESCRIPTION: 
 9 # 
10 #       OPTIONS: ---
11 #  REQUIREMENTS: ---
12 #          BUGS: ---
13 #         NOTES: ---
14 #        AUTHOR: linkscue (scue), linkscue@gmail.com
15 #  ORGANIZATION: 
16 #       CREATED: 2014年08月03日 01时14分25秒 CST
17 #      REVISION:  ---
18 #===============================================================================
19 
20 # FTP上传文件
21 # 依赖于 ncftp 命令
22 put_action(){
23     srv=$1                                      # FTP Server Addr
24     port=$2                                     # FTP Server Port
25     user=$3                                     # FTP Client User
26     passwd=$4                                   # FTP Client Passwd
27     dir=$5                                      # 文件存放目录
28     file=$6                                     # 需上传的文件
29     tmp=/tmp/$(basename $0)_$$.txt
30     cat <<-EOF >$tmp
31     cd $dir
32     put $file
33     bye
34     EOF
35     ncftp -u $user -p $passwd $srv $port <$tmp
36     rm -f $tmp
37 }
38 
39 put_action 192.168.1.201 21 scue 123 / dropbear.sh 

 

posted @ 2014-08-03 01:33  scue  阅读(2416)  评论(0编辑  收藏  举报