Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Net::FTP Cannot login to server

by pimperator (Acolyte)
on Jul 26, 2014 at 19:56 UTC ( [id://1095178] : perlquestion . print w/replies, xml ) Need Help??

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

Salutations monks

I followed the Monk's guide to FTP::Net and I still cannot get my script to connect to the server. Here's my code

#!/usr/bin/perl use strict; use warnings; use Net::FTP; my $host = ""; my $user = "ftpuser"; my $password = "qwerty"; my $f = Net::FTP->new($host, Port => 22, Debug=> 1) or die "Cannot ope +n $host\n"; $f->login($user,$password) or die "cannot log $user in\n"; my $dir = "/home/files/cool_beans"; $f->cwd($dir) or die "Can't cwd to $dir\n"; my @files = $f->ls; print @files, "\n";

Here's the output on the terminal

bucephalus:Desktop barney$ perl Net::FTP>>> Net::FTP(2.77) Net::FTP>>> Exporter(5.66) Net::FTP>>> Net::Cmd(2.29) Net::FTP>>> IO::Socket::INET(1.33) Net::FTP>>> IO::Socket(1.34) Net::FTP>>> IO::Handle(1.33) Net::FTP=GLOB(0x7ff09b0b55d8)<<< SSH-2.0-OpenSSH_6.0p1 Debian-4+deb7u2 Cannot open

Am I doing something wrong? Or is it the server? I can login using FileZilla with the same credentials. I am using a Windows device and the server appears to be Unix; could this be an issue with logging in? I tried running the same script on my Mac device and on a Unix cluster and same failure.

My goal is to parse through a lot of files on the server and print the output locally on my device. Is there another way to accomplish this task?

tusen takk monks

Replies are listed 'Best First'.
Re: Net::FTP Cannot login to server
by AppleFritter (Vicar) on Jul 26, 2014 at 20:20 UTC
    my $f = Net::FTP->new($host, Port => 22, Debug=> 1) or die "Cannot ope +n $host\n";

    Port 22 is SSH, not FTP; try 21.

    Two tips for future debugging, too:

    1. Your script died when trying to create an FTP connection, before ->login() was even called, which is a clue that the credentials were not the problem.

    2. Pay attention to output, especially if you specifically request debugging information. This line:

      Net::FTP=GLOB(0x7ff09b0b55d8)<<< SSH-2.0-OpenSSH_6.0p1 Debian-4+deb7u2

      is a dead giveaway that you're connecting to the wrong service even if you don't have the port numbers for common services memorized.

      Thanks for the reply. These were the credentials I was given, it worked for FileZilla. I changed the port number to 21 and get a timeout error. Any clues to why this might occur?

        Are you sure that it is ftp that you should be talking? There are also FTPS and SFTP.

Re: Net::FTP Cannot login to server
by 1s44c (Scribe) on Jul 27, 2014 at 11:35 UTC

    Don't use FTP if you can use HTTP, SSH, SCP, Rsync, or something less arcane and troublesome.

    FTP has firewall issues.