in reply to Re: trouble while ftping through Perl Script
in thread trouble while ftping through Perl Script

Ok! I have decided to use the Net::FTP::Common module
But, when I execute my code, I get the error
error logging in: at /usr1/duser/ActivePerl-5.8/lib/site_perl/5.8.2/Net/FTP/Common.pm line 127. Can't call method "cwd" on an undefined value at /usr1/duser/ActivePerl-5.8/lib/site_perl/5.8.2/Net/FTP/Common.pm line 276.
Is it a problem with my code or with the installation of the module? But, after installation of the module I got a message "Successfully installed Net-FTP-Common version 3.7 in ActivePerl 5.8.2.808." Here is my code
use Net::FTP::Common; my $common_cfg = { Host => 'ftp.servername.com', User => 'username', Pass => 'password', RemoteDir => '/files' }; my $ftp = Net::FTP::Common->new($common_cfg, Debug => 0); $ftp->get("somefile.txt"); $ftp->quit;

Replies are listed 'Best First'.
...That's how perlmonks works [Re: Re: Re: trouble while ftping through Perl Script]
by bronto (Priest) on Apr 29, 2004 at 13:38 UTC

    Provide problems, and we (try to) provide solutions, that's how perlmonks works. If you just told us your problems with Net::FTP at your first post, everyone had benefits out of it: you would have had the solution, and others would not have wasted their time trying to guess what the problem was and how to solve it

    Update: By the way, when you are going to use objects in Perl it's always better to check that you really have one before trying to use it. I mean:

    use Net::FTP; # this is wrong, because you cwd without checking # if $ftp is really an object or it is undef # (new() failed) $ftp = Net::FTP->new("some.host.name", Debug => 0) ; $ftp->cwd("/pub") ; # This is right instead, and it comes straight from # Net::FTP's documentation # See how every method call is checked for success $ftp = Net::FTP->new("some.host.name", Debug => 0) or die "Cannot connect to some.host.name: $@"; $ftp->login("anonymous",'-anonymous@') or die "Cannot login ", $ftp->message; $ftp->cwd("/pub") or die "Cannot change working directory ", $ftp->message; $ftp->get("that.file") or die "get failed ", $ftp->message; $ftp->quit;

    Ciao
    --bronto


    The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
    --John M. Dlugosz
      I had tried that too. I gives me an error message: Cannot login Login incorrect.
      I know the userid and password are correct....I've tested them directly. Just one doubt, the password contains some back slashes and $ sign. Can that be a problem? But, I am enclosing the password in quotes, so that should not be problem....??? My code is:
      use Net::FTP; my $ftp = Net::FTP->new("ftp.server.com", Debug => 0) or die "Cannot c +onnect to some.host.name: $@"; my $username = 'username'; my $password = 'pa\ss\wor$d$'; $ftp->login($username,$password) or die "Cannot login ", $ftp->message +; $ftp->cwd("/files") or die "Cannot change working directory ", $ftp->m +essage; $ftp->ls("/files") or die "get failed ", $ftp->message; $ftp->quit;
        Why not just apply some simple trouble shooting. Eliminate the password issue (if possible):
      • change the password for that user to something that doesn't have \'s or $'s in it long enough to test your script.
      • or try another user that does not have special charaters in the password.

        Plankton: 1% Evil, 99% Hot Gas.
Re: Re: Re: trouble while ftping through Perl Script
by gellyfish (Monsignor) on Apr 29, 2004 at 12:18 UTC

    The problem is that it is not logging in correctly. I would suggest that you use Net::FTP directly whereby you can get the error messages directly:

    use strict; use Net::FTP; my $client = Net::FTP->new('ftp.servername.com', Debug => 1) or die "Cannot connect : $@\n"; $client->cwd('/files') or die $client->message(); $client->get('somefile.txt') or die $client->message(); $client->quit()

    /J\

      I have tried that too. I gives me an error message:
      Cannot login Login incorrect.
      I know the userid and password are correct....I've tested them directly. Just one doubt, the password contains some back slashes and $ sign. Can that be a problem? But, I am enclosing the password in quotes, so that should not be problem....???
      My code is:
      use Net::FTP; my $ftp = Net::FTP->new("ftp.server.com", Debug => 0) or die "Cannot c +onnect to some.host.name: $@"; my $username = 'username'; my $password = 'pa\ss\wor$d$'; $ftp->login($username,$password) or die "Cannot login ", $ftp->message +; $ftp->cwd("/files") or die "Cannot change working directory ", $ftp->m +essage; $ftp->ls("/files") or die "get failed ", $ftp->message; $ftp->quit;

        my $password = 'pa\ss\wor$d$';

        Well that looks alright in the example you give, but what do you get when you print the $password as you have it in your actual code?

        /J\