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

I am still confused on the use of this function:
$ftp->get(REMOTE_FILE, LOCAL_FILE)
I point to a perl script on an ftp server which pops up in my browser. The script, which is filling out a form and clicking the save button, saves a file on the ftp server which I want it to do. What I also need to happen is the file that just got saved on the ftp server needs to be saved on my pc in the temp folder. The file name is 00000001.610 that I want in the temp folder on my pc. This also is the name of the file on the ftp server. So would the syntax look like this:
$ftp->get(00000001.610,00000001.610);
Thanks in advance

20050520 Edit by Corion: Changed title from 'Net:::FTP'

Replies are listed 'Best First'.
Re: How Do I Use Net::FTP
by davido (Cardinal) on May 17, 2005 at 15:33 UTC

    Per the POD:

    LOCAL_FILE may be a filename or a filehandle. If not specified, the file will be stored in the current directory with the same leafname as the remote file.

    Personally I would use the filehandle option. That way you can do your own checking as to whether or not open succeeded. Also remember that if you're sending non-textual data, you need to specify binary transfer mode, and binmode for your open filehandle.


    Dave

      Dave, Is this something that would work?
      my $filehandle = "C:/Temp"; $ftp->get("00000001.610,$filehandle);
      Am I even close? Thanks

        No, you should have read the docs on open, and probably perlopentut.

        What I suggested above is that you open a file for output, and use its filehandle. You do that like this:

        $ftp->binary; open my $filehandle, '>', 'c:/Temp/00000001.610' or die "Couldn't open output file.\n$!"; binmode $filehandle; $ftp->get("00000001.610", $filehandle); close $filehandle or die 'Couldn't close output file.\n$!"; $ftp->quit;

        That is untested, so use at your own risk. Also, eliminate the $ftp->binary; line, and the 'binmode $filehandle;' line if you are dealing with text files.


        Dave

Re: How Do I Use Net::FTP
by davidrw (Prior) on May 17, 2005 at 15:41 UTC
    I assume it's just an example snippet, but be aware that 00000001.610 and "00000001.610" are very different.
    perl -le 'sub x{print shift}; x("0000001.610")' # 0000001.610 perl -le 'sub x{print shift}; x(0000001.610)' # 1610
      You assumed correctly.