FTP解释脚本
你不妨试试看用 $HOME/.netrc 设定的方式来做ftp:
例如你要从 hostA ftp 一个文档 zzz 到 hostB 的 /tmp 里,
可以先 setup $HOME/.netrc 如下:
remoteHost=hostB
remoteLogin=xxx
remotePswd=yyy
remoteDir=/tmp
filename=zzz
echo "machine $remoteHost login $remoteLogin password $remotePswd
macdef downloadFile
cd $remoteDir
bin
put $filename
quit
" > $HOME/.netrc
chmod 600 $HOME/.netrc
# $HOME/.netrc 设定好后,执行 ftp 如下,就不需密码:
echo "\$ downloadFile" | ftp $remoteHost
# 如果可以了,你再依样画虎做个shell脚本批量处理即可。
thx
② 从FTP服务器上下载一个可执行文件的脚本或命令,并运行这个程序。如何写
echo open 10.131.29.242 >>d:\ftp.txt
echo 123>>d:\ftp.txt
echo 123>>d:\ftp.txt
echo lcd c:\tmp >>d:\ftp.txt
echo get a\bb.exe >>d:\ftp.txt
echo y >> d:\ftp.txt
echo bye >>d:\ftp.txt
c:
ftp -s:d:\ftp.txt
del d:\ftp.txt
③ shell脚本的FTP程序有点看不懂,请教解释
1. -i表示关闭交互式登陆方式,就是就不问你什么帐号密码了
-n表示不使用.netrc自动登陆。.netrc是ftp的初始化文件
2. open 10.1.128.112 3839,这3839表示端口
3. 没错,是用户名密码
4. 这个应该错了在我这ftp下没这个命令,我这是centos 5.4
ftp> put FTPPerformanceTest/2.sh
local: FTPPerformanceTest/2.sh remote: FTPPerformanceTest/2.sh
local: FTPPerformanceTest/2.sh: No such file or directory
执行shell脚本也出错
local: FTPPerformanceTest/2.sh: No such file or directory
改成put $1 $2后正常
5. ftp2put 20Apt.txt 20最终反应到shell脚本中的命令就是put 20Apt.txt 20,即把20Apt.txt上传到ftp服务器并改名为20
6. sleep 1 表示休眠1秒对吧?,对的。
④ Linux FTP脚本
试一下在put前,设置传输模式为二进制,即用 binary 命令。
另外,是不是你的winrar不支持.gz格式的,结果导致它报错?你可以试一下用其他格式压缩,或者干脆就不压缩,直接传一个文本或图片文件过去看看有没有传输的问题。
⑤ 求高手解答这段shell脚本是什么意思------关于FTP的
等于在命令行输入ftp -i -n -v 回车
然后手动输入这几行命令
open 192.168.1.10 回车 这行打开ftp:///192.168.1.10
user *** *** 回车 这行输入用户名
bye 回车 这行退出ftp
就一个IP,不用for,而且这个for没用,改成 for host in aaa 结果还是一样的
除了登录ftp,然后显示ftp登录后服务器显示的信息,然后直接退出,什么都没做
⑥ suse 的 b shell 脚本中怎么写 ftp 命令
重点是这一句:ftp -v -i -n 218.200.245.84</home/mediation/config.billing>>/home/mediation/log/ftpcdr.log
从这一句看出所有的FTP命令都是从“/home/mediation/config.billing”此文件中读取的,所以你要的FTP命令都在这个文件中。
⑦ ftp使用perl脚本
#!/usr/bin/perl -w
use Net::FTP;
use POSIX qw(strftime); #这个是我当时用来抓时间的可以省略
my $remotefile;
my $localfile;
my $dir = 'E:/CDR/trunk/'; #本地存放路径
my $host;
my $password;
my $ftp;
#1. get begin
$host='192.168.1.105'; #被FTP的远程IP
$password='hahahaha'; #ftp的密码
$ftp=Net::FTP->new($host) or die "cannot connect to ftp server $host!\n";
$ftp->login("root",$password);
$ftp->cwd("/AP/CDR"); #远程抓取的路径
if ( -d "$dir/$host" ) { #这个条件句是用来判断本地目录192.168.1.105是否存在,不存在就创建
}
else {
system "mkdir -p $host";
}
print "the list of /ap/cdr from $host!!\n"; #列出远程目录的所以非目录文件,并抓取符合条件的文件
&list("/");
$ftp->quit;
#1. get end
sub list() #list类,判断文件类型的核心
{
my $current = $_[0];
my @subdirs;
$ftp->cwd($current);
my @allfiles = $ftp->ls();
foreach (@allfiles){
if(&find_type($_) eq "d"){ #如果是目录则打印并忽略掉
print "this floder!!\n";
}
else{
my $tmp = "$_";
print $tmp."\n";
if($tmp=~/adf/){ #判断包含adf则抓取,当然可以扩展正则方法
$remotefile=$tmp;
$localfile = "$dir/$host/".$remotefile;
$ftp->binary();
$ftp->get($remotefile,$localfile)
or die "Could not get remotefile:$remotefile\n";
print "download $remotefile complete from $host!!\n";
}
}
}
}
sub find_type{
my $path = shift;
my $pwd = $ftp->pwd;
my $type = '-';
if ($ftp->cwd($path)) {
$ftp->cwd ($pwd);
$type = 'd';
}
return $type;
}
老大 我自己执行是可以的, 把分给我吧
⑧ windows下ftp脚本 我参考网上的一些例子,写了以下两个脚本,可是系统总是循环执行第一句
名字不能叫ftp.bat,换一个别的名字!
⑨ FTP脚本怎么设置啊
代码发给你了:
#!/usr/bin/perl
-w
use
Net::FTP;
use
POSIX
qw(strftime);
#这个是我当时用来抓时间的可以省略
my
$remotefile;
my
$localfile;
my
$dir
=
'E:/CDR/trunk/';
#本地存放路径
my
$host;
my
$password;
my
$ftp;
#1.
get
begin
$host='192.168.1.105';
#被FTP的远程IP
$password='hahahaha';
#ftp的密码
$ftp=Net::FTP->new($host)
or
die
"cannot
connect
to
ftp
server
$host!\n";
$ftp->login("root",$password);
$ftp->cwd("/AP/CDR");
#远程抓取的路径
if
(
-d
"$dir/$host"
)
{
#这个条件句是用来判断本地目录192.168.1.105是否存在,不存在就创建
}
else
{
system
"mkdir
-p
$host";
}
print
"the
list
of
/ap/cdr
from
$host!!\n";
#列出远程目录的所以非目录文件,并抓取符合条件的文件
&list("/");
$ftp->quit;
#1.
get
end
sub
list()
#list类,判断文件类型的核心
{
my
$current
=
$_[0];
my
@subdirs;
$ftp->cwd($current);
my
@allfiles
=
$ftp->ls();
foreach
(@allfiles){
if(&find_type($_)
eq
"d"){
#如果是目录则打印并忽略掉
print
"this
floder!!\n";
}
else{
my
$tmp
=
"$_";
print
$tmp."\n";
if($tmp=~/adf/){
#判断包含adf则抓取,当然可以扩展正则方法
$remotefile=$tmp;
$localfile
=
"$dir/$host/".$remotefile;
$ftp->binary();
$ftp->get($remotefile,$localfile)
or
die
"Could
not
get
remotefile:$remotefile\n";
print
"download
$remotefile
complete
from
$host!!\n";
}
}
}
}
sub
find_type{
my
$path
=
shift;
my
$pwd
=
$ftp->pwd;
my
$type
=
'-';
if
($ftp->cwd($path))
{
$ftp->cwd
($pwd);
$type
=
'd';
}
return
$type;
}