Click to See Complete Forum and Search --> : Perl FTP Script


perfectly_dark
09-23-2003, 05:49 PM
Hi,

I'm by no stretch a perl programmer, but I do know programming in other languages so please bare with me ;)

I wrote a Perl script a few days ago that takes a file and FTPs in to a web site. It worked on one computer but now I tried it on another computer and it doesn't work anymore. Heres the code:

#!/usr/bin/perl
#
use strict;
use warnings;
use Net::FTP;
my $ftp = Net::FTP->new("website.com", Debug => 3);
$ftp->login("username", "password");
$ftp->cwd("/htdocs");
$ftp->put("/etc/rc.d/file.file", "file.file");
$ftp->quit;


The address, username, password are all replaced by their proper values. The problem is that when I run this, I get an error message:
"Can't call method "login" on an undefined value at ./rc.ftpscript2 line 8"
Does anyone know what's wrong with this script or the system? Do I need to install some modules or something?

Thx in advance

ph34r
09-23-2003, 06:19 PM
Do you have the stuff that provides Net::FTP installed?

dchidelf
09-23-2003, 09:16 PM
You can try something like this.


my $ftp = Net::FTP->new("website.com", Debug => 3);
if(! defined $ftp){
print "ftp failed: $@\n";
}


If Net::FTP is working correctly it should tell you what is wrong.

perfectly_dark
09-25-2003, 05:58 PM
Thank you very much. I used the if statement to check what the problem was and sure enough it couldn't find the host. So I did some thinking and found out that my firewall was blocking the connection (stupid me). Thx