PDA

View Full Version : ftp using cgi script


div31
11-25-2002, 05:42 PM
hi,

I have no experience with CGI.
In my projet, i am creating a flat file in unix with the data entered by the users in an html form. when the Submit button is hit, the flat file needs to be FTP'd to a remote server. Can i do this by calling a CGI script when the Submit button is hit?

If yes, can somebody please provide me with the script used to FTP.

Thanks.

mr_evans2u
03-14-2003, 08:40 PM
I just saw your post, are you still needing this to be answered?

Robin
04-03-2003, 05:08 PM
Hi,

I have this same question about using a cgi script to ftp a text file. I have not used cgi scripts but think this might be my only option... I have an html form that I have previously used a SurveyRecorder with to send the results into a flat text file on the server. This functionality is not longer supported on the server.

Any help available?

mr_evans2u
04-03-2003, 05:29 PM
This is a little ftp script that I use in my programs. Hope this helps.

use strict;
use Net::FTP;

$| = 1;

# This is the directory where the file is located
my $directory = "directory you want to connect to";

# Change to the directory you want the file to go into
chdir "your home directory";

# Download file from the right server
my $ftp = Net::FTP->new( "server you want to connect to ");

die "Cannot login: $@ "unless $ftp;

# Log into the server
$ftp->login("user id", "password");

# Change to the right directory
$ftp->cwd("$directory")
or die qq{Cannot switch to "$directory": $@ };

# Change to binary transfer mode
$ftp->binary;

# Turn on hash marks
$ftp->hash(1);

# File name(s) you want to download
foreach my $filename ("filename")

{
# This is for command line only
print "About to download $filename from $directory.\n";
$ftp->get($filename)
or die qq{Cannot get $filename from $directory. \n};
$ftp->put ($filename)
or die qq{Cannot put $filename to $directory. \n};


print "Done.\n";

}

$ftp->quit;

Robin
04-03-2003, 06:35 PM
Thanks for that script! I will give it a try and post the results.