jonnyfolk has asked for the wisdom of the Perl Monks concerning the following question:
I have been trying to expand this idea in order to download files from multiple directories within the starting directory. However I have run into a problem that the script locates the correct file in the directory, but it dies on the 'get' command with message "Couldn't get $filename - 1". Using the simpler script of yesterday the file downloads perfectly, and I have compared the paths created in the two scripts and they seem to be the same. Yet the simple one works but not the other...
I wonder if someone can let me know what might be causing this
The code I wrote yesterday (works):
my $home="mysite.com"; my $username="username"; my $password="password"; my $directory="data/edit"; my $filename="data.txt"; my $filename1="path/to/file/data.txt"; my $ftp = Net::FTP->new("$home") or die "Can't connect: 1 $@\n"; $ftp->login($username, $password) or die "Couldn't login - 1\n"; $ftp->cwd($directory) or die "Couldn't change direct +ory - 1\n"; $ftp->get($filename, $filename1) or die "Couldn't g +et $filename - 1\n"; my @lines = $ftp->ls("/data/edit"); $ftp->quit;
The following is the code to get the directories and write the files (dies):
my $home="mysite.com"; my $username="username"; my $password="password"; my $directory="/data"; my $dirname ="path/to/dir"; my $ftp = Net::FTP->new("$home") or die "Can't connect: 1 $@\n"; $ftp->login($username, $password) or die "Couldn't login - 1\n"; $ftp->cwd($directory) or die "Couldn't change direct +ory - 1\n"; my @lines = $ftp->ls("/data"); foreach (@lines) { my $directory1 = "$directory/$_"; my $homedir = "$dirname/$_"; unless ( /back_up|contact/) { my @lines1 = $ftp->ls($directory1); foreach my $filename (@lines1) { print "<br>directory1: $directory1<br>"; print "<br>homedir: $homedir<br>"; my $filename1 = "$homedir/$filename"; $ftp->get($filename, $filename1) or die "Couldn't get $fil +ename - 1\n"; } } } $ftp->quit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::FTP downloading multiple files from multiple directories
by valdez (Monsignor) on Oct 29, 2003 at 17:57 UTC | |
|
Re: Net::FTP downloading multiple files from multiple directories
by castaway (Parson) on Oct 30, 2003 at 06:33 UTC |