http://qs321.pair.com?node_id=1029255

vin.hephaistion has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I am using Net::FTP module to access the FTP server which is configured by me itself on another machine. I have configured the FTP server for anonymous access as well as authorized access. Just to understand the module functioning, i used a list of username and password to try out on my file server Wrote the following code trying combinations of username and password:

eval { $ftp = Net::FTP->new($in, Debug => 0); $ftp->login($username,$password); }; if(!($@)) { print SLOG "Connected FTP: for $username and $password \n"; }

It is giving me... Connected to FTP: for all combinations of the username and password.

Note: 1) I want to notify that the FTP server has anonymous login. 2) I don't want it to be accessed by any other username and password except for the valid ones using Net::FTP

  • Comment on Accessing FTP server using Net::FTP with any username and password
  • Download Code

Replies are listed 'Best First'.
Re: Accessing FTP server using Net::FTP with any username and password
by vinoth.ree (Monsignor) on Apr 18, 2013 at 05:13 UTC
    login ([LOGIN [,PASSWORD , ACCOUNT ] ])

    Log into the remote FTP server with the given login information. If no arguments are given then the Net::FTP uses the Net::Netrc package to lookup the login information for the connected host. If no information is found then a login of anonymous is used. If no password is given and the login is anonymous then anonymous@ will be used for password.


    All is well
Re: Accessing FTP server using Net::FTP with any username and password
by derby (Abbot) on Apr 18, 2013 at 13:51 UTC

    It's been a while since I've dealt with Net::FTP but from what I recall, the login method does not raise an exception, you need to do that.

    eval { $ftp = Net::FTP->new( $in, Debug => 0 ); $ftp->login( $username, $password ) or die "Cannot login ", $ftp->message; }; if( ! ( $@ ) ) { print ... }
    -derby

      It worked!!