Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a script called bho.pl. I am doing this on a
Windows NT platform and I must get a file on a Unix
Platform.

The snippet is below.


#!/perl/bin require Exporter; use lib ("/perl/lib/Net"); use Net::FTP; $ftp = Net::FTP->new("droid.fit.qut.edu.au", Passive => True) or die "Can't open connect: $@\n"; $ftp->login("n2212811","asturias7") or die "Can't login: $@\ +n"; $ftp->cwd(); $ftp->cwd("/n2212811/public_html/scripts") or die "Can't open connec +t: $@\n"; $ftp->get("exp.txt"); $ftp->quit;
The error messages are strange.
First I received this:

C:\webmaster\public_html\cgi-bin>perl bho.pl

Can't login:

Then I fixed this problem by fixinf up my login
Password and I re-ran the script.
Then I got this error
Message:

C:\webmaster\public_html\cgi-bin>perl bho.pl

Can't open connect:


Please tell me, does the problem lie
In the fact that it can't
Find the hostname?


This is the first time I am doing Net::FTP in perl...
If you have a portion of code that works, instead of me
Having to import the Net::FTP library,
It would be just as easily
Appreciated...

...just enough to get the job done
As simply as possible.
Thanks.

Warmest Regards,

Isaac
Pereira

Replies are listed 'Best First'.
Re: I Need to Use Net::FTP but its not working?
by eg (Friar) on Feb 04, 2001 at 13:26 UTC

    Hi Isaac.

    First of all, if that's your real username/password CHANGE YOUR PASSWORD.

    Second, the problem is most likely that the path your sending is wrong. I suggest doing the ftp manually, cd'ing into the directory you want and then doing pwd to find out what the real path is. Almost certainly it's not /n2212811/public_html/scripts (which would be hanging right off the the root), but probably something like /mnt/u2212/n2212811/public_html/scripts.

    Also, you want to use $! in your die statements. $@ is for checking eval's. (my bad, see Fastolfe's comment below)

    Good luck.

      I think Net::FTP uses $@ for its error messages (whether that's good or bad is out of the scope of this post). $! would not make sense, as most of the errors you would get out of Net::FTP do not map to standardized system error messages/numbers, thus would be unsuitable for $!.
Re: I Need to Use Net::FTP but its not working?
by eLore (Hermit) on Feb 04, 2001 at 20:21 UTC
    I doubt it's the root of the problem, but I'd take a look at the use lib "/perl/lib/net" line. I haven't read that much on win32 perl-ing, but that looks like it should be C:\perl\lib\net or something... You might be loading a different version of Net::FTP than you're expecting.

    Your code *should* be working. (Then again, you're on NT)

    Here's a working ex: (hostname changed)

    (Note, almost exactly from the documentation for Net::FTP @CPAN):

    #!/usr/bin/perl -w use Net::FTP; $ftp = Net::FTP->new("myhost", Debug => 0); $ftp->login("anonymous",'test@user.com') || die "Could not log in\n"; $ftp->cwd("/pub/incoming") || die "Could not cd\n"; $ftp->get("that.file") || die "Could not find the right file\n"; $ftp->quit;
Re: I Need to Use Net::FTP but its not working?
by Anonymous Monk on Feb 05, 2001 at 01:24 UTC
    I also noticed that you have the use lib as:
    > use lib ("/perl/lib/Net");

    but then you say this

    > use Net::FTP;
    since you are defining the root lib directory as Net, it might be that you can't include it correctly. It is probably looking for Net::Net::Ftp.

    maybe change your use lib to:

    > use lib ("/perl/lib");
    or
    > use lib ("C:\perl\lib");
    since you are using win

    -cymbopus