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;
}