Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Net::Ftp->login problem

by KianTern (Acolyte)
on Oct 31, 2007 at 09:36 UTC ( #648201=perlquestion: print w/replies, xml ) Need Help??

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

I'm writing a script that should connect to a number of ftp sites and fetch data. I've put all the access information into files so I won't have any of it inside the code. I've successfully logged in and fetched needed data from one of the ftps using this script but login fails while connecting to the other ftps. The passwords are correct and I can login using the basic Linux ftp client. I've tried to hardcode the access info into the script but still no use. Does anyone know what could be the problem?

Replies are listed 'Best First'.
Re: Net::Ftp->login problem
by marto (Cardinal) on Oct 31, 2007 at 09:47 UTC
    If, as you cliam this works command line then there is something wrong with your code. Do check that each operation is successful, and if not display (or otherwise alert you) to the fact an error has occured? If you post your code (remove sensitive data, passwords etc) someone will try and help you. Please read How do I post a question effectively? and the PerlMonks FAQ if you have not already done so.

    Martin
Re: Net::Ftp->login problem
by syphilis (Bishop) on Oct 31, 2007 at 09:51 UTC
    Might help if you provide the Debug => 1 argument to the new() constructor.

    Do the ftp connections that fail also fail from a script that attempts to make just the *one* connection (to that ftp site) ?

    Some code might help - just a simple demo (with names and passwords changed, of course).

    Cheers,
    Rob
Re: Net::Ftp->login problem
by apl (Monsignor) on Oct 31, 2007 at 09:53 UTC
    Are you testing / displaying the error-codes returned?

    Failing that, have you tried manually performing the steps your program would take?

    You might also consider showing us the relevant code. It's possible you have a phase-of-the-moon problem that only occurs the Nth time a piece of code gets executed.

      I do have permission those ftp accounts where created for my usage. Firewall not blocking i can access the sites with standard ftp client all the access info was copy/pasted from the origial documents. I also tried to copy paste the user and pass from my .pwd file and it works great and I still can connect to one remote and one local ftps using this code
      #!/usr/bin/perl -w use Net::FTP; use strict; my $site = shift @ARGV; my $dir = shift @ARGV; my $sd = "/SCRIPTS"; my $wd = "/DATA"; my $access_file="$sd/ftp_access_info/$site.pwd"; my $ftp; # name for the ftp class my $host; # ftp name my $user; # user name for ftp my $pass; # password for ftp my @files; # list of files on the ftp #get access info from file open(FTP_ACCESS, "<" , $access_file); my @ftp_access = <FTP_ACCESS>; chomp @ftp_access; close (FTP_ACCESS); #set access info $host = $ftp_access[0]; $user = $ftp_access[1]; $pass = $ftp_access[2]; print "|$host|\n|$user|\n|$pass|\n"; #get directory listing print "Connecting\n"; $ftp=Net::FTP->new("$host",Timeout=>240) or die "connect\n"; print "Loging in\n"; $ftp->login("$user","$pass") or die "login\n"; print "Getting File lists\n"; $ftp->cwd($dir) if $dir; @files=$ftp->dir or die "dir\n"; print "$_\n" foreach @files; $ftp->quit;
        I am a little bit confused by something, perhaps I am not understanding you correctly, just to clear things up let me ask a question that may sound silly. Do you expect the code above to login to one ftp server after another, and perform the same operation? If this is the case then you will need to look at some sort of loop (a for loop say) so that the process is repeated for each .pwd file you have in a folder.
        Try setting the ftp to PASSIVE mode after connecting. You can set it during the connection initiation string if you would like by using it as an %option (read the Net::FTP documentation for specifics).

        $ftp->pasv;

        Here is a reasonable explanation of the difference between Active and Passive ftp and what is happening that might require a PASV connection.



        "The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it." - Terry Pratchett
        Firewalls are known to block programs

Re: Net::Ftp->login problem
by nimdokk (Vicar) on Oct 31, 2007 at 12:07 UTC
    I'm going to reiterate the comment someone else made: enable the debug mode. It can be very helpful with figuring out what is wrong. To enable debug mode, simply use the following line:

    $ftp=Net::FTP->new("$host",Timeout=>240,Debug=>1) or die "connect\n";
    Also, I would recommend looking at the logs from the server you are attempting to connect to. If you do not have access to these logs, kindly ask your friendly neighborhood sysadmin to help you out.
      Thank you all but I guess problem was not from my side now everything (almost) works as it should
Re: Net::Ftp->login problem
by narainhere (Monk) on Oct 31, 2007 at 11:30 UTC
    Try giving you user name as
    machine-username@firewall-username@hostname
    and password as
    machine-password@firewall-password
    if you are behind a firewall.

    The world is so big for any individual to conquer

Re: Net::Ftp->login problem
by Anonymous Monk on Oct 31, 2007 at 09:50 UTC
    1. you are hardcode incorrectly
    2. you are reading incorrectly
    3. you don't have permission (firewall...)
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://648201]
Approved by andreas1234567
Front-paged by derby
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2021-04-20 12:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?