in reply to Re^3: How Do I Use Net::FTP
in thread How Do I Use Net::FTP

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

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

    Is this a CGI script? Check your server's error log. You'll probably find an answer there.

    Also, change your $ftp->get(.....) line as follows:

    $ftp->get("00000001.txt", $filehandle) or die "Couldn't get 00000001.txt\n$!";

    Then run the script again, and check your error logs. Also, if this is a CGI script, use CGI::Carp with the fatalsToBrowser setting. See the documentation for CGI::Carp at the link provided in this paragraph. Use it as a development tool, and then remove it once things are working as they should.

    Most likely problems could include a problem getting the file, or a problem opening for output.


    Dave

Re^5: How Do I Use Net::FTP
by radiantmatrix (Parson) on May 17, 2005 at 20:40 UTC
    If this is a CGI-type script (as it appears to be), then it is running on the server. If it is running on the server, then Net::FTP cannot save a file to your machine, only the machine where it actually executes.

    This is different from how a Java applet (for example) operates, by executing on your local machine. Perl scripts accessed in CGI mode execute only on the server.

    My apologies if I misunderstood your question.


    The Eightfold Path: 'use warnings;', 'use strict;', 'use diagnostics;', perltidy, CGI or CGI::Simple, try the CPAN first, big modules and small scripts, test first.