user1095332
user1095332

Reputation: 442

FTP in perl error?

Is there anything wrong the script bewlow, because I just can't login..... And I'm sure I'm using the right username and password. (Cannot login Login incorrect.)

sub UploadToFTPServer()
{
my $filename = shift;


$ftp = Net::FTP->new($FTPSERVER, Debug => 0) ;
if ($ftp) {     
    eval {
        $ftp->login($USERNAME,$PASSWORD)   or warn "Cannot login ", $ftp->message;
        $ftp->binary();

        $ftp->putfile($filename) or warn "Cannot upload ($filename)", $ftp->message;
        $ftp->quit();
    };
}
else {
    warn "Cannot connect to $FTPSERVER: $@";
}
}

Upvotes: 0

Views: 539

Answers (4)

Bill Ruppert
Bill Ruppert

Reputation: 9026

Try $ftp->put instead of $ftp->putfile. I don't see putfile in the documentation.

Upvotes: 0

gpojd
gpojd

Reputation: 23085

Start your script off with this:

use strict;
use warnings;

Then make sure that perl doesn't try to interpolate anything in your un/pw.

my $USERNAME = '[email protected]'; ## notice the single quotes
my $PASSWORD = 'mypass';

Given your error, it should work with those changes. It would have been easier to catch if the strict and warnings pragmas were used from the start.

Upvotes: 3

killzone
killzone

Reputation: 91

Use the module "Net::FTP::Simple"

@send = Net::FTP::Simple->send_files({
    username        => $user,
    password        => $pass,
    server          => $host,
    remote_dir      => $path,
    debug_ftp       => 0,
    files           => [
        $file,
    ],
});

print "The following files were retrieved successfully:\n\t",
    join("\n\t", @send), "\n"
        if @send;

Upvotes: 0

Øyvind Skaar
Øyvind Skaar

Reputation: 2338

Are you sure your testing from the same IP?

Also, try printing the username & password with quotes around them, as gpojd suggested.

Upvotes: 0

Related Questions