Current location: Hot Scripts Forums » Programming Languages » Perl » Upload a file to a fix web folder of a website without using FTP software


Upload a file to a fix web folder of a website without using FTP software

Reply
  #1 (permalink)  
Old 05-09-06, 04:36 AM
sujata_ghosh sujata_ghosh is offline
Wannabe Coder
 
Join Date: May 2006
Posts: 181
Thanks: 0
Thanked 0 Times in 0 Posts
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.

thanks in advance.
Sujata.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 05-09-06, 01:20 PM
Millennium's Avatar
Millennium Millennium is offline
Wannabe Coder
 
Join Date: Nov 2003
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 05-10-06, 03:03 AM
sujata_ghosh sujata_ghosh is offline
Wannabe Coder
 
Join Date: May 2006
Posts: 181
Thanks: 0
Thanked 0 Times in 0 Posts
thanks Millennium!

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 05-10-06, 03:25 AM
Millennium's Avatar
Millennium Millennium is offline
Wannabe Coder
 
Join Date: Nov 2003
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
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:

http://perldoc.perl.org/Net/FTP.html

If using Net::FTP does not work you can use the CGI module to upload files too.

http://perldoc.perl.org/CGI.html
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 05-10-06, 10:10 AM
sujata_ghosh sujata_ghosh is offline
Wannabe Coder
 
Join Date: May 2006
Posts: 181
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Millennium!

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

the code i am trying as follows:

Code:
#!/usr/bin/perl -w

my $DATA_DIR = 'xxxx';   # Path of data directory

my $DEFAULT_UPLOAD_DIR = 'xxx'; 

my $login    = $query->param('login');
my $password = $query->param('pass');
my $action   = $query->param('ac');

my ($dir);

if ($query->param('BT_Exit')) { $action = ''; }


if ($action eq 'admin') {
	print $query->header;
	if ($login && $password)  {
		&admin($query, $login, $password);
	} else {
		print &PagePassword($NAME_TITLE{'common_admin'});
	}
} elsif ($action eq 'upload') {
	print $query->header;
	if ($dir = &check_password('guest', $login, $password)) {
	print &Upload($query, $dir);	
	} else {
		print &BadPassword($NAME_TITLE{'common_member'});
	}


} else {
	print $query->redirect($FORM_URL);

}

sub Upload  {

	my($query, $upload_dir) = @_;
    my($file_query, $file_name, $size, $buff, $time, $bytes_count);
	$size = $bytes_count =0;
	print "file_query = $file_query1<br><br>";

	$_ = $file_query = $query->param('file1');
	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,1024)) {
   	$size += $bytes_count;
        print FILE $buff;

    }
    close(FILE);

}
can you tell me in this way it will work or not or I have to choce the file using HTML file upload box only?

thanks once again for your time and effort.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP upload prob minority ASP 1 06-27-05 09:35 AM
Programmer Needed (Forums Software) LandonCowling Job Offers & Assistance 2 01-17-05 06:02 AM
move files around an ftp server, with php file upload script? wapchimp PHP 2 12-19-04 08:27 AM
FS: Prozilla Memberships (Turnkey Sites) - $10-15 less than Retail! rockergrrl General Advertisements 0 08-11-04 01:05 AM
Upload file to table so ONLY files tied to primary key are displayed in record? grafixDummy PHP 4 12-20-03 05:28 PM


All times are GMT -5. The time now is 10:58 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.