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

#!/usr/bin/perl 1 use Net::FTP; 2 my $host="domain.org"; 3 my $directory="public_html/tmp"; 4 my $name="xxx.pdf"; 5 $ftp=Net::FTP->new($host,Timeout=>240); 6 $ftp->login("username","password"); 7 $ftp->cwd($directory); 8 $ftp->put($name); 9 $ftp->quit;

The above works fine. I've removed the error checking for brevity. It is in the cgi-bin folder on my web page server.

The file $name (xxx.pdf) must exist in the same folder as the perl program. (cgi-bin)

The file $name (xxx.pdf) is put into the folder "public_html/tmp".

What I want to do is get a file from my local machine (c:\tmp\xxx.pdf) and put it on the server in "public_html/tmp".

Thanks!

Replies are listed 'Best First'.
Re: ftp a file
by Illuminatus (Curate) on Oct 11, 2010 at 17:27 UTC
    Keep in mind that scripts run from a web server run as the userid of the server (unless the setuid bit is set, and the server allows such things). It also may not be using the home directory you expect. Since you have removed the error-checking, I cannot see what you are currently checking for.

    fnord

Re: ftp a file
by kcott (Archbishop) on Oct 11, 2010 at 18:19 UTC

    The documentation for Net::FTP discusses local and remote files in the Overview and shows the two-argument form of put() in Methods.

    You could also change the local directory beforehand and then proceed as you are currently doing (bearing in mind the caveats posted by Illuminatus).

    If you have further problems, please reinstate the error checking and add use strict; and use warnings; to your code.

    -- Ken