Upload a file to a fix web folder of a website without using FTP software
Hi to all!
I am trying to implement a script which upload a fixed gif and html files from a fixed local directory into a fixed folder of our website, which will be happened everyday, so that i am trying to some automated process so that I don't have to user FTP software to upload that file everyday. I have tried the following methode, its uploading the file from local machine to the web directory through a form, but the problem is it can't read the file size, so its copying 0 bite size file. (but if chose the file from this Form and say upload its working fine, but if I supply the local directiry path its not working) the code as follows:
Code:
my $file_query1 = 'D:\work for people\k****ij\oil1.shtml';
sub Upload {
my($query, $upload_dir) = @_;
my($file_query, $file_name, $size, $buff, $time, $bytes_count);
$size = $bytes_count =0;
$_ = $file_query1;
s/\w://;
s/([^\/\]+)$//;
$_ = $1;
s/\.\.+//g;
s/\s+//g;
$file_name = $_;
open(FILE,">$upload_dir/$file_name") || &Error("Error opening file $file_name for writing, error $!", 1);
binmode FILE;
$time=time();
while ($bytes_count = read($file_query,$buff,2096)) {
$size += $bytes_count;
print FILE $buff;
}
close(FILE);
print "completed<br><br>";
}
in the code this following portion is not working:
-------------------------------------------------------------------------------------
open(FILE,">$upload_dir/$file_name") || &Error("Error opening file $file_name for writing, error $!", 1);
binmode FILE;
$time=time();
while ($bytes_count = read($file_query,$buff,2096)) {
$size += $bytes_count;
print FILE $buff;
}
close(FILE);
I simply want to use a CGI or perl script to FTP or transfer some perticular file with from a fixed local folder to a fixed webfolder, but without usiing manual FTP client software.
can anyone help me with this perticular matter? if you need any more info please let me know. if you think is there any other way please let me know.
setup a task or service on your windows box that opens a perl program, in the perl program use Net::FTP to make the file transfers to the FTP server. Since this is automated it's not really a CGI script, CGI scripts are run from a browser.
actully we have a CGI form by which we publish daily report in the form of HTML, for our website. For that I am looking for auto FTP facility when we submit the form data, on that time it will called the FTP script and execute so that, that image and html file will automatically uploaded to the webserver, we don't have to manually FTP these file afterwards using FTP solftware.
As per your conversation i have came accross that I can use Net::FTP, I have tried the code following code which i have got the following code from the net:
Code:
#!/usr/bin/perl -w
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use Net::FTP;
$hostname = 'xxx';
$username = 'xxx';
$password = 'xxx';
# Hardcode the directory and filename to get
$home = '/temp';
$filename = 'image.jpg';
# Open the connection to the host
$ftp = Net::FTP->new($hostname); # construct object
$ftp->login($username, $password);
$ftp->cwd($home);
$ftp->ls($home);
$ftp->get($filename);
$ftp->quit;
have a look whether it is rite or wrong. on execution it gave me following errors:
Code:
Software error:
[Wed May 10 03:01:52 2006] FTP.pm: Can't locate Net/FTP.pm in @INC (@INC contains: /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_perl/5.005/i386-linux /usr/lib/perl5/site_perl/5.005 .) at ftp.pl line 7. BEGIN failed--compilation aborted at ftp.pl line 7.
Please let me know what i have to follow? is the above perl code for FTP is ok.
that error message is telling you the Net::Ftp module is not found, which generally means it's not installed. You have what looks like an old version of perl installed: 5.005, you should upgrade to the latest version of perl. You can read the Net::FTP documentation which will give you a better idea of if your script is good and will do what you want:
I Have requested to our provider of Webserver to install this module. I don't know whether they will be able to do or not I am not sure.
Meanwhile the code which I have tried in below, within that can you give me some idea:
In the CGI form, which i was talking in my last post, if i give full path of the local file and define the path to whom it will be upload, it will work apart from FTP