in reply to Re: FTP Unix -> NT
in thread FTP Unix -> NT

hi again,
actually I do already have a login, just too lazy to login! :-)

OK, the code I have is as follows, but it's just a simple test thing to try and get FTP.pm to work.

#!/usr/bin/perl -w

use Net::FTP;

my $hostname='216.74.109.245';
my $user='username';
my $password='password';
my $ftp=Net::FTP -> new($hostname) or die ("Connect failed");
$ftp->login($username,$password) or die ("Cant log in");
$ftp->binary;
$ftp->cwd("/public_ftp") or die ("Cant change directory");
$ftp->put("mystuff.txt") or die ("Cant put stuff on server");
$ftp->quit

It produces:
Name "main::username" used only once: possible typo at ./ftp-logs.pl line 9.
Cant log in at ./ftp-logs.pl line 9.

However, I am pretty sure my login information is correct and I can connect via the unix FTP prompt fine.

I'm also slightly concerned whether it's working ok because I had to manually create the Net::Config.pm file by copying it from cpan because it didn't exist in my system originally, but was required by the Net::FTP.pm module.

Hmm i'm confused...
thanks,
Tom

Replies are listed 'Best First'.
Re: Re: Re: FTP Unix -> NT
by vek (Prior) on Nov 14, 2002 at 17:01 UTC
    You are storing the username in $user but you are attempting to login using $username.

    -- vek --

      That's a very good point, I always miss the obvious things like that, cheers

Re: Re: Re: FTP Unix -> NT
by pg (Canon) on Nov 14, 2002 at 17:03 UTC
    Yes, it will not work, read this:
    Name "main::username" used only once: possible typo at ./ftp-logs.pl line 9. his "

    use "use strict;" ALL the time. You mis-spelled, one place it is $username, and then it is $user.
Re: Re: Re: FTP Unix -> NT
by Mr. Muskrat (Canon) on Nov 14, 2002 at 17:05 UTC

    If the server, username and password aren't changed very often, you might just try simplifying it down to:

    #!/usr/bin/perl -w use strict; use Net::FTP; my $ftp = Net::FTP->new('216.74.109.245') or die "Server not found"; $ftp->login('username','password') or die $ftp->message(); #$ftp->binary(); $ftp->ascii(); # you probably want to send it as ASCII instead of bin +ary if it is a text file $ftp->cwd("/public_ftp") or die $ftp->message(); $ftp->get("mystuff.txt") or die $ftp->message(); $ftp->quit;

    You will see that I removed the variables that you were using only once. I also let the Net::FTP session provide it's own error messages.