[KLUG Members] FTP code

Jamie McCarthy members@kalamazoolinux.org
Tue, 16 Oct 2001 01:42:36 -0400


scott.thurmond@pfsfhq.com (Scott Thurmond) writes:

> Thanks.  I found a perl example and it worked.  Can you tell me
> where perl writes log information?

Wherever you tell it to.  Perl itself doesn't log anything, it
spits error messages to STDERR, but of course individual scripts
can write logs wherever they want.  I'd have to see your script.

> I setup the directory /usr/local/ftpfiles for the script to put
> files in.  After running it and the files appeared in this
> directory, I removed the ftpfiles subdirectory to see what
> error messages I would get.  To my surprise, I didn't get any -
> and the script appeared to complete.  I checked and it had not
> put the file in another location, it had not created the
> directory and I couldn't find a log that it wrote to.
> 
> Any suggestions?

Sounds like your script is not correctly checking its returned
error values, a common problem with programmers unfortunately...

Here's a sample program to do what (it sounds like) you want:

#!/usr/bin/perl -w
use strict;
use Net::FTP;
chdir "/usr/local/ftpfiles" or die "no chdir: $!";
my $ftp = Net::FTP->new("ftp.kernel.org", Debug => 0);
die "no ftp object: $@" unless $ftp;
$ftp->login("anonymous", "me\@privacy.net");
$ftp->cwd("/pub");
$ftp->get("README") or die "get failed, reason unknown";
$ftp->quit;

Change the "Debug" value from 0 to 1 and it'll spit out a lot
of details about the transaction.
--
 Jamie McCarthy
 jamie@mccarthy.vg