in reply to trouble while ftping through Perl Script

Why do you want to avoid the use of Net::FTP? I certainly think it would be the best tool for the job.

You said you found the code you quote on perlmonks, but you don't tell us where, and you only quote a small excerpt of the code. After some super-searching, it turns out the script you found is meant to connect to a ftp server through a firewall - it depends on the gateway having specific functionality.

If you absolutely refuse to have anything to do with Net::FTP (why? Why? WHY?), perhaps you could use Expect; and talk to the FTP prompts through that.

  • Comment on Re: trouble while ftping through Perl Script

Replies are listed 'Best First'.
Re: Re: trouble while ftping through Perl Script
by shilpam (Sexton) on Apr 29, 2004 at 12:04 UTC
    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;

      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;

      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;