Hi folks,
I have to dowload files like the one with a .dat extension and having "qu" in their name (just an example)
I would have liked to write in my code someting like $ftp->get(*qu*.dat); I think I barely tried everything between *,.,/
I finally write a code using regular expressions, (see at the end) but it is a bit long and I ll have also to copy,move files I don't know the entire name.
Would you know an easier way to do it?
Thanks a lot and have a great WE!
*******************my code************************
# general subroutine with parts that can be commented out and add as arguments
# calling it: ftp(url,directory,pattern) // because anonymous connexion + no file to put in (pattern represents the cracteres we want the file to have in its name,pb
nly one set of caracteres can be recognized or have to change the code depending on how many patterns we have...)
sub ftp
{
print "starting ftp subroutine\n";
my $url=$_[0];
my $directory=$_[1];
my $getFilename;
my $pattern=$_[2];
my $ftp= Net::FTP->new($url) or die "Can't connect: $@\n";
$ftp->login() or die "Could'nt login in anonymous\n";
my @list=$ftp->ls($directory) or die "Could'nt list directory $directory\n";#get the list of files in this remote directory
$ftp->cwd($directory) or die "Could'nt change directory into $directory\n";#change directory
foreach (@list)
{
my $prefix=$directory."/";#to have just the name of the file (and not the directory extention before)
$_=~/$prefix/;
$getFilename=$';
if ($getFilename=~ /$pattern/)
{
$ftp->get($getFilename) or die "Could'nt get $getFilename\n";
print "$getFilename downloaded\n";
}
$ftp->quit() or warn"Couldn't quit, oh well...";
print "done with ftp subroutine\n";
return @list;
}
I have to dowload files like the one with a .dat extension and having "qu" in their name (just an example)
I would have liked to write in my code someting like $ftp->get(*qu*.dat); I think I barely tried everything between *,.,/
I finally write a code using regular expressions, (see at the end) but it is a bit long and I ll have also to copy,move files I don't know the entire name.
Would you know an easier way to do it?
Thanks a lot and have a great WE!
*******************my code************************
# general subroutine with parts that can be commented out and add as arguments
# calling it: ftp(url,directory,pattern) // because anonymous connexion + no file to put in (pattern represents the cracteres we want the file to have in its name,pb
sub ftp
{
print "starting ftp subroutine\n";
my $url=$_[0];
my $directory=$_[1];
my $getFilename;
my $pattern=$_[2];
my $ftp= Net::FTP->new($url) or die "Can't connect: $@\n";
$ftp->login() or die "Could'nt login in anonymous\n";
my @list=$ftp->ls($directory) or die "Could'nt list directory $directory\n";#get the list of files in this remote directory
$ftp->cwd($directory) or die "Could'nt change directory into $directory\n";#change directory
foreach (@list)
{
my $prefix=$directory."/";#to have just the name of the file (and not the directory extention before)
$_=~/$prefix/;
$getFilename=$';
if ($getFilename=~ /$pattern/)
{
$ftp->get($getFilename) or die "Could'nt get $getFilename\n";
print "$getFilename downloaded\n";
}
$ftp->quit() or warn"Couldn't quit, oh well...";
print "done with ftp subroutine\n";
return @list;
}