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

What I am looking for is a way to copy a file from an ftp server directory to a client's hard drive into a folder. This is what I have tried without any success. I get an error message stating: bad hostname.
#!/perl/bin use Net::FTP; my $File = Net::FTP->new("ftp.26.190.158.98") or die "Couldn't connect: $@\n"; my $login = "name"; my $passwd = "pwd"; #$File->login($login,$passwd); #$File->cwd("folder"); #$File->put("DEC0610.001"); #$File->close();
Any help would be appreciated

Replies are listed 'Best First'.
Re: copy a file from ftp to clients hard drive
by davidrw (Prior) on May 13, 2005 at 16:52 UTC
    * The argument to Net::FTP->new() is the hostname, which should be an IP address (e.g. '26.190.158.98') or a hostname (e.g. 'ftp.yourhost.com'). So it looks to me like your "bad hostname" error message is correct and your hostname is just malformed.
    * Should probably change $File to something like $ftp so it's not misleading.

    for reference, from Net::FTP docs (looks like this is exactly the functionality you need):
    use Net::FTP; $ftp = Net::FTP->new("some.host.name", Debug => 0); $ftp->login("anonymous",'-anonymous@'); $ftp->cwd("/pub"); $ftp->get("that.file"); $ftp->quit;

    Update: Btw, you said you wanted to go from a ftp server to a client machine, but your sample code has a put() call and not a get() ....
Re: copy a file from ftp to clients hard drive
by pboin (Deacon) on May 13, 2005 at 16:50 UTC

    Well, the error msg means what it says: 'bad hostname'.

    Try it without the 'ftp.' portion.

Re: copy a file from ftp to clients hard drive
by artist (Parson) on May 13, 2005 at 16:56 UTC
    Try after removing 'ftp' from the hostname ie.. Net::FTP->new('26.190.158.98')
    --Artist
      No error messages now...thanks guys but the file is not being copy into the clients pc. Should it be GET instead of the PUT function?
Re: copy a file from ftp to clients hard drive
by sh1tn (Priest) on May 13, 2005 at 17:50 UTC
    Please, change the values and test or just make sure
    you have Debug turned on (working example):
    use strict; use warnings; use diagnostics; use Net::FTP; my $file = 'npulse-0.53p2.tar.gz'; my $host = 'ftp.ttm.bg'; my $user = 'anonymous'; my $pass = '-anonymous@'; my $dir = 'pub/Linux/admin/'; my $ftp = Net::FTP->new($host, Debug => 1); $ftp->login($user,$pass); $ftp->cwd($dir); $ftp->get($file); $ftp->quit;


      After running the above code, this is the message I received.
      $BADREF = undef; process $BADREF 1,2,3; $BADREF->process(1,2,3); Uncaught exception from user code: Can't call method "login" on an undefined value at c:\Inetpub\domains\rvnuccio.com\doytest\cgi-bin\ftpPass.pl line 15 +.
Re: copy a file from ftp to clients hard drive
by salva (Canon) on May 13, 2005 at 19:19 UTC
    you would also like to try LWP::Simple getstore function.
Re: copy a file from ftp to clients hard drive
by ktross (Deacon) on May 13, 2005 at 16:49 UTC
    A shot in the dark, but I would try replacing the double quotes in:
    my $File = Net::FTP->new("ftp.26.190.158.98")
    with single quotes:
    my $File = Net::FTP->new('ftp.26.190.158.98')
    Update: Duely noted, thanks.

    Spem Successus Alit

      "." is not an operator inside either types of quotes. Your two snippets are identical.

      The problem is that "ftp.26.190.158.98" is not a valid IP address or domain name. "26.190.158.98" (without the leading "ftp.") would be a valid IP address, and possibly what the OP needs to use.