in reply to How Do I Use Net::FTP

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

Replies are listed 'Best First'.
Re^2: How Do I Use Net::FTP
by Doyle (Acolyte) on May 17, 2005 at 15:46 UTC
    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

        Dave, At least no more errors are popping up. Here is my code:
        #!/usr/local/bin/perl -w use Net::FTP; use Sys::Hostname; $hostname = hostname(); $hostname = '*****.com'; # ftp host $username = '*******'; # username $password = '*******'; # password $home = '/doytest/cgi-bin/Data/*.txt'; $ftp = Net::FTP->new($hostname); # Net::FTP constr +uctor $ftp->login($username, $password); # log in w/userna +me and password $pwd = $ftp->pwd; # get current dir +ectory open my $filehandle, '>', 'c:/Temp/00000001.610' or die "Couldn't open output file.\n$!"; $ftp->get("00000001.txt", $filehandle); close $filehandle or die "Couldn't close output file.\n$!"; # Now, output HTML page. print <<HTML; Content-type: text/html <HTML> <HEAD> <TITLE>Download Files</TITLE> </HEAD> <BODY> <B>Current working directory:</B> $pwd<BR> Files to download: <P> HTML @entries = $ftp->ls($home); # slurp all entr +ies into an array print "@entries \n\n"; print "$filehandle\n"; print <<HTML; </BODY> </HTML> HTML $ftp->quit;
        The file does not copy into my Temp folder on my c: drive. Possible answers? Thanks