请问如何编写shell脚本实现ftp自动上传?

发表于:2007-06-08来源:作者:点击数: 标签:
请问如何使用脚本实现ftp的自动上传? 初步想法如下: #!/bin/sh ftphostip #ftp需要输入用户名和密码,我不知道ftp命令是否有提供参数可以输入用#户名和密码,如果有该如何使用呢? #而且,还想实现上传功能,是否可以 put filename #感觉这样子是不行,大

请问如何使用脚本实现ftp的自动上传?
初步想法如下:
#!/bin/sh
ftp hostip
#ftp需要输入用户名和密码,我不知道ftp命令是否有提供参数可以输入用#户名和密码,如果有该如何使用呢?
#而且,还想实现上传功能,是否可以
put
filename

#感觉这样子是不行,大家还有什么提议呢?
#反正我的目的是要想运行这个脚本,它就会帮我自动的把文件上传到另外一台服务器上,而不需要我输入任何的命令

 artxing 回复于:2003-11-05 00:53:02
写了个脚本ftpup.sh

内容为:

[code:1:1342efc2e4]#!/bin/sh

F="wangxu.ftp"

echo "open 192.168.0.1 21"     > $F
echo "user wangxu password"     >> $F
echo "bin"                      >> $F
echo "mput $1"                  >> $F
echo "bye"                      >> $F

ftp -i -in < $F
rm -rf $F[/code:1:1342efc2e4]

上传的时候运行:
./ftpup filename

 arleneclearcase/" target="_blank" >cc 回复于:2003-11-05 00:55:36
容易,看看我写过得一个脚本就知道了,虽然只是一个小脚本,不过本着GPL的精神拿来给大家看看吧,


#!/bin/sh 

#created by arlenecc 
#last update date 20030928 
# RainLow backup utility version 1.0 -- 28/09/2003 
# http://www.rainlow.com 
# By arlenecc <[email protected]

echo -e " \t\t \033[1;31m RainLow Tech. ToolKit \033[m version 1.0rc1 -- 16/08/2003 \n" 
echo -e "############################################################" 
echo -e " This software may be used and distributed according to " 
echo -e "the terms of the GNU General Public License (GPL) provided" 
echo -e "credit is given to the original author. " 
echo -e "\t\t\t \033[1;31m Copyright (c) 2002 Rainlow Tech. \033[m \n" 
echo -e "\t\t\t\t All rights reserved \n\n\n" 
echo -e "############################################################" 







echo -e "\t\t\t Welcome to \033[1;31m Rainlow Tech. Research \033[m \n" 
echo -e "\t\t\t\t \033[1;32m http://www.rainlow.com \033[m \n" 

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin 

echo -e " please enter the path you want to backup [/usr/local]:" 

read _BACKUP 
if [ -z "$_BACKUP" ]; then 
_BACKUP=/usr/local 
fi 
#echo -e " please enter the path you want to put backup file(must to be /path/) [/home/]:" 

#read _TO 
#if [ -z "$_TO" ]; then 
#_TO=/home/ 
#fi 
echo -e " please enter the ip address of the ftp server you want to backup to [192.168.1.89]:" 

read _HOST 
if [ -z "$_HOST" ]; then 
_HOST=192.168.1.89 
fi 
echo -e " please enter the username of the ftp server you want to backup to [arlenecc]:" 

read _USERNAME 
if [ -z "$_USER" ]; then 
_USER=arlenecc 
fi 
echo -e " please enter the password of the ftp server you want to backup to [aln7980xwq]:" 

read _PASS 
if [ -z "$_PASS" ]; then 
_PASS=aln7980xwq 
fi 
OF=BACKUP-$(date +%Y%m%d%k%M).tar.gz 
tar -cvzf $OF $_BACKUP 
ftp -n << ! 
open $_HOST 21 
user $_USER $_PASS 
prompt 
put $OF 
bye 

rm -f $OF 

echo -e "\t\t \033[1;32m SUCCESS \033[m \n" 
echo -e "\t \033[1;32m $_BACKUP \033[m are backup as \033[1;32m $OF \033[m and successfully transfered to \033[1;32m $_HOST \033[m \n"

 kinux 回复于:2003-11-05 01:51:34
[quote:391e597ab2="arlenecc"][/quote:391e597ab2]

老大, 开始怀凝你是不是红袖了.. 

 cynosurelu 回复于:2003-11-05 09:57:25
arlenecc你牛:)

 text2002 回复于:2003-11-10 11:27:40
顶起来看

原文转自:http://www.ltesting.net