> I have this little piece of code: > > > -- CUT -- > #!/usr/bin/perl > > use strict; > use warnings; > use Net::FTP; > > my $address = "localhost"; > my $port = 21; > my $user = "test"; > my $pass = "test"; > my $sourcedir = "/test/"; > my $sourcemask = "*"; > my $destdir = "/tmp/test/"; > > my $ftp = Net::FTP->new( > $address, > Timeout => 30, > Debug => 0, > Port => $port, > ) or die "Error in connect"; > $ftp->login($user, $pass) or die "Error in login"; > $ftp->cwd($sourcedir) or die "Error in cwd"; > $ftp->binary(); > for ($ftp->ls($sourcemask)) { > $ftp->get("$_", "$destdir$_") or die "Error in get"; > } > -- CUT -- > > > Now, if I put in some wrong values I get the expected "Error in ****". > The unexpected behaviour happens when the destination directory doesn't > exist and I get this output: > > > Cannot open Local file /tmp/test/test.xml: No such file or directory > at ./test.pl line 25 > Error in get at ./test.pl line 25. >
What is unexpected about this? Your error is being caught, and the first line is just a warning, and a pretty useful one at that. > > Changing the loop to: > > > for ($ftp->ls($sourcemask)) { > my $ret = undef; > eval { $ret = $ftp->get($_, "$destdir$_") }; > die "Error in get" unless defined $ret; > } > > > Doesn't work either. Well it works, just doesn't do what you think it should do. Generally 'eval' is used to catch exceptions which would otherwise cause the script to die, the failure of get does not throw an exception, so the eval works the same as if it wasn't there. Besides you would need to check $@ if the eval were catching an exception. > Any way to prevent this other than checking if the destination directory > exists? > What is the actual behaviour you are after? What are you trying to prevent? Why wouldn't you want to check for the existence of the destination directory, considering for completeness you should be checking for it? For efficiency's sake you shouldn't even bother connecting if the destination doesn't exist, at least in the snippet you have shown us. http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>