脚本:让sftp看起来像是ftp


脚本:让sftp看起来像是ftp
 
本脚本的目的是,让sftp命令启动时,看起来和ftp一模一样。就是输入用户,远程地址等内容。
 
01
#!/bin/sh
02
 
03
# mysftp.sh -- make sftp start up more like ftp
04
 
05
echo -n "User account: "
06
read account
07
 
08
if [ -z "$account" ]; then
09
    exit 0;
10
fi
11
 
12
if [ -z "$1" ]; then
13
    echo -n "Remote host: "
14
    read host
15
    if [ -z "$host" ]; then
16
        exit 0
17
    fi
18
else
19
    host=$1
20
fi
21
 
22
exec /usr/bin/sftp -C $account@$host
运行结果:
01
$ mysftp
02
User account: taylor
03
Remote host: intuitive.com
04
Connecting to intuitive.com...
05
taylor@intuitive.com's password:
06
 
07
sftp> quit
08
 
09
 
10
$ mysftp intuitive.com
11
User account: taylor
12
Connecting to intuitive.com...
13
taylor@intuitive.com's password:
14
 
15
sftp> quit
这个脚本中,唯一需要注意的技巧是最后一行的exec命令。它会用指定的应用来代替当前正在运行的shell。因为,你知道在调用了sftp命令后就可以结束了,那么这种方法的效果是要好于将shell挂起等待,直到sftp命令执行完毕。
 

相关内容

    暂无相关文章