写了一个查看FTP文件更新的工具
2007-03-29 15:57
597 查看
最近没什么事情做,偷懒不想每次都登陆FTP查看,就写了这么一个PERL程序。
命令格式:在cmd中运行,FtpFileFind-v1.0.exe ftp.txt
ftp.txt为FTP服务器的配置文件,可以把自己想要查询的FTP服务器加进去,格式参 考原来的配置。
输出:cmd输出,并且输出到当前文件夹的一个RESULT.txt的文件中。
后语:此程序是PERL所写,就是想偷懒不用上FTP就知道最近更新了哪些文件,欢迎大家提出新的更新建议,方便大家使用。
提示:如果在cmd中不能显示中文,键入chcp 936后回车就ok!
#!/usr/bin/perl
print "*********************************************************/n";
print " FTP Find Tool/n";
print " Build by YangKang /n";
print "*********************************************************/n";
$ARGC=@ARGV;
if ($ARGC!=1) {
print "/n Usage: $0 ftpListFile/n";
print "/n Attention:Please make sure that your dictionary-file was exist/n";
print " or you have got the right address and port!/n";
print "/n Good Luck!";
exit;
}
use Net::FTP;
#use Strict;
use Socket;
my $ftpfile=$ARGV[0];
my $logfile="RESULT.txt";
my $logo="UPDATE TIME:";
sub find_type
{
my $path = shift;
my $a=substr($path,0,1);
return $a;
}
##########################################################
sub list
{
my $current = $_[0];
my @subdirs;
$currenttmp=substr($current,0,2);
if($currenttmp eq "//")
{
$current=substr($current,1);
}
$ftp->cwd($current);
my @dir=$ftp->dir($current);
foreach(@dir)
{
my $path=$ftp->pwd();
my $filetype=&find_type($_);
$filename=substr($_,55);
if(&find_type($_) eq "d")
{
if($filename ne ".")
{
if($filename ne "..")
{
$currentpath=$path . "/".$filename;
push @subdirs,$currentpath;
}
}
}
else
{
if(!($_ =~ /^total/))
{
#print "$_/n";
my @filetime=split //s+/,$_; #tiem of file
my $filemonth=$filetime[5];
my $fileday=$filetime[6];
my $filehour=$filetime[7];
my $temptime="$logo $filemonth $fileday $filehour";
$test=$ftp->mdtm($filename);
if($test>$now)
{
#print LOG "$_/n";
print $path."/$filename $temptime/n";
print LOG ($path."/$filename $temptime/n");
}
}
}
}
foreach (@subdirs)
{
&list($_);
}
}
##########################################################
#($name, $aliases, $proto) = getprotobyname('tcp');
#($name, $aliases, $port) = getservbyname($port, 'tcp') unless $port =~ /^/d+$/;
#read from file
open(USERFILE,$ftpfile)||die("Can't open the user's list!/n");
open(LOG,">RESULT.txt")||die("Can't open the result file!/n");
$now=time();
$now -= (24 * 3600*3 ); #day before yesterday
@data=<USERFILE>;
foreach(@data)
{
my @a=split //s+/,$_;
$address=shift(@a);
$port=shift(@a);
$username=shift(@a);
$password=shift(@a);
print "Testing on $address:$port username:$username;pass:$password .../n";
print LOG ("/n");
print LOG ("/n");
print LOG ("==========new update file in FTP Server of $address==========/n");
print LOG ("/n");
print LOG ("/n");
$ftp=Net::FTP->new($address,Port => $port);
die "couldn't connect!/n" unless $ftp;
$ftp->login($username,$password);
if($ftp->cwd('/'))
{
print "FTP Server:$address can be connected now!/n";
print "Analysing $address............/n";
&list('/');
print "Finish Analysing $address/n";
print "############################################/n";
}
else
{
print "FTP Server:$address cann't be connected now!/n";
}
$ftp->quit();
}
close (USERFILE);
exit(0);
ftp.txt格式:
ip(或者域名) port name password 中间以空格分隔。
如下:
xxxx.ihep.ac.cn 21 xxx xxx
命令格式:在cmd中运行,FtpFileFind-v1.0.exe ftp.txt
ftp.txt为FTP服务器的配置文件,可以把自己想要查询的FTP服务器加进去,格式参 考原来的配置。
输出:cmd输出,并且输出到当前文件夹的一个RESULT.txt的文件中。
后语:此程序是PERL所写,就是想偷懒不用上FTP就知道最近更新了哪些文件,欢迎大家提出新的更新建议,方便大家使用。
提示:如果在cmd中不能显示中文,键入chcp 936后回车就ok!
#!/usr/bin/perl
print "*********************************************************/n";
print " FTP Find Tool/n";
print " Build by YangKang /n";
print "*********************************************************/n";
$ARGC=@ARGV;
if ($ARGC!=1) {
print "/n Usage: $0 ftpListFile/n";
print "/n Attention:Please make sure that your dictionary-file was exist/n";
print " or you have got the right address and port!/n";
print "/n Good Luck!";
exit;
}
use Net::FTP;
#use Strict;
use Socket;
my $ftpfile=$ARGV[0];
my $logfile="RESULT.txt";
my $logo="UPDATE TIME:";
sub find_type
{
my $path = shift;
my $a=substr($path,0,1);
return $a;
}
##########################################################
sub list
{
my $current = $_[0];
my @subdirs;
$currenttmp=substr($current,0,2);
if($currenttmp eq "//")
{
$current=substr($current,1);
}
$ftp->cwd($current);
my @dir=$ftp->dir($current);
foreach(@dir)
{
my $path=$ftp->pwd();
my $filetype=&find_type($_);
$filename=substr($_,55);
if(&find_type($_) eq "d")
{
if($filename ne ".")
{
if($filename ne "..")
{
$currentpath=$path . "/".$filename;
push @subdirs,$currentpath;
}
}
}
else
{
if(!($_ =~ /^total/))
{
#print "$_/n";
my @filetime=split //s+/,$_; #tiem of file
my $filemonth=$filetime[5];
my $fileday=$filetime[6];
my $filehour=$filetime[7];
my $temptime="$logo $filemonth $fileday $filehour";
$test=$ftp->mdtm($filename);
if($test>$now)
{
#print LOG "$_/n";
print $path."/$filename $temptime/n";
print LOG ($path."/$filename $temptime/n");
}
}
}
}
foreach (@subdirs)
{
&list($_);
}
}
##########################################################
#($name, $aliases, $proto) = getprotobyname('tcp');
#($name, $aliases, $port) = getservbyname($port, 'tcp') unless $port =~ /^/d+$/;
#read from file
open(USERFILE,$ftpfile)||die("Can't open the user's list!/n");
open(LOG,">RESULT.txt")||die("Can't open the result file!/n");
$now=time();
$now -= (24 * 3600*3 ); #day before yesterday
@data=<USERFILE>;
foreach(@data)
{
my @a=split //s+/,$_;
$address=shift(@a);
$port=shift(@a);
$username=shift(@a);
$password=shift(@a);
print "Testing on $address:$port username:$username;pass:$password .../n";
print LOG ("/n");
print LOG ("/n");
print LOG ("==========new update file in FTP Server of $address==========/n");
print LOG ("/n");
print LOG ("/n");
$ftp=Net::FTP->new($address,Port => $port);
die "couldn't connect!/n" unless $ftp;
$ftp->login($username,$password);
if($ftp->cwd('/'))
{
print "FTP Server:$address can be connected now!/n";
print "Analysing $address............/n";
&list('/');
print "Finish Analysing $address/n";
print "############################################/n";
}
else
{
print "FTP Server:$address cann't be connected now!/n";
}
$ftp->quit();
}
close (USERFILE);
exit(0);
ftp.txt格式:
ip(或者域名) port name password 中间以空格分隔。
如下:
xxxx.ihep.ac.cn 21 xxx xxx
相关文章推荐
- 一个可以查看 Linux 当前缓存了哪些大文件的小工具
- git中如何查看一个文件的修改(更新)历史
- wget用法wget是一个从网络上自动下载文件的自由工具。它支持HTTP,HTTPS和FTP协议,可以使用HTTP代理.
- 用 AutoHotkey 做一个文件查找工具之四:根据输入实时更新过滤文件列表
- 一个查看PE文件内容的小工具——CliPeViewer
- 发现一个好用的Android文件访问工具--es文件管理器,可以在同局域网下的浏览器中查看手机中的文件
- enca - 一个linux下面转换windows txt文件到linux下面可以查看txt的工具
- grunt配置太复杂?发布一个前端构建工具,简单高效,自动跳过未更新的文件
- EasySegyViewer v1.0 一个用来查看SEGY文件的工具(开源)
- 一个简单的elf文件头查看工具
- 用 AutoHotkey 做一个文件查找工具之四:根据输入实时更新过滤文件列表
- 发布一个EMF图像文件查看分析工具
- wget是一个从网络上自动下载文件的自由工具,支持通过HTTP、HTTPS、FTP三个最常见的TCP/IP协议下载,并可以使用HTTP代理
- VC8实现的一个PC端查看TSK主题文件的工具,以及由其引出的VC8MFC程序脱离.net框架分发问题
- java项目上线时摘取更新文件工具
- [Linux][2014-09-23] enca Linux下 文件编码 查看 转换 工具
- 一个简单的使用wininet的http/ftp文件下载程序
- 使用PB调用API自动更新(非FTP模式)(四、统计复制文件数量函数F_CONNECT_COPYCOUNT)
- 更新了一个新版本的editplus 语法文件(for nagios)
- 如何使用Process Monitor查看一个http请求都读取了哪些文件