基于sftp的shell编程

基于sftp的shell编程

两个组件

(1)expect

首先安装expect 需要两个tar.gz 如下所示

 tar zxvf tcl8.4.19-src.tar.gz
 cd tcl8.4.19/unix && ./configure
 make 
 make install


tar zxvf expect5.45.tar.gz
cd expect5.45
./configure --with-tcl=/usr/local/lib --with-tclinclude=../tcl8.4.19/generic
make
make install
expect<<-END
spawn sftp -oPort=${PORT} $USER@$HOST
expect {
    "(yes/no)?" {
        send "yes\r"
    }
    "*assword:" {send "${PASSWD}\r"}
}
expect "sftp>"
send "cd ${DEST_DIR}\n"
expect "sftp>"
send "lcd ${LOC_DIR}\r"
expect "sftp>"
send "mput $file_path $newfile_path\r"
expect "sftp>"
send "quit\r"
END

(2)lftp

首先安装lftp

gnutls-2.12.23-22.el6.x86_64.rpm
lftp-4.0.9-1.el6_5.1.x86_64.rpm

rpm -ivh gnutls-2.12.23-22.el6.x86_64.rpm
rpm -ivh lftp-4.0.9-1.el6_5.1.x86_64.rpm
lftp -u ${USER},${PASSWORD} sftp://${IP}:${PORT} <<EOF
cd ${SEVERDIR}/
lcd ${CLIENTDIR}
mput $file_path
mv $SEVERDIR"/"$file_upload $SEVERDIR"/"$newfile
by
EOF

lftp shell相关

lftp :~> ?
    !<shell-command>                     (commands)                           alias [<name> [<value>]]             attach [PID]
    bookmark [SUBCMD]                    cache [SUBCMD]                       cat [-b] <files>                     cd <rdir>
    chmod [OPTS] mode file...            close [-a]                           [re]cls [opts] [path/][pattern]      debug [<level>|off] [-o <file>]
    du [options] <dirs>                  exit [<code>|bg]                     get [OPTS] <rfile> [-o <lfile>]      glob [OPTS] <cmd> <args>
    help [<cmd>]                         history -w file|-r file|-c|-l [cnt]  jobs [-v]                            kill all|<job_no>
    lcd <ldir>                           lftp [OPTS] <site>                   ln [-s] <file1> <file2>              ls [<args>]
    mget [OPTS] <files>                  mirror [OPTS] [remote [local]]       mkdir [-p] <dirs>                    module name [args]
    more <files>                         mput [OPTS] <files>                  mrm <files>                          mv <file1> <file2>
    [re]nlist [<args>]                   open [OPTS] <site>                   pget [OPTS] <rfile> [-o <lfile>]     put [OPTS] <lfile> [-o <rfile>]
    pwd [-p]                             queue [OPTS] [<cmd>]                 quote <cmd>                          repeat [OPTS] [delay] [command]
    rm [-r] [-f] <files>                 rmdir [-f] <dirs>                    scache [<session_no>]                set [OPT] [<var> [<val>]]
    site <site-cmd>                      source <file>                        torrent [-O <dir>] <file|URL>...     user <user|URL> [<pass>]
    wait [<jobno>]                       zcat <files>                         zmore <files>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值