LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-14-2005, 11:46 PM   #1
xboxter
LQ Newbie
 
Registered: May 2005
Posts: 6

Rep: Reputation: 0
Arrow Urgent Help: Perl FTP Script Using NET::FTP


Hello All,

I have a question regarding a project that I'm working on. I'm using PERL and NET::FTP to write a small FTP web application script that will allow users on my Local Area Network to upload files to me. It will be running on my web server. I'm running RedHat Linux 9 and the Apache Web Server. I got the connection and login components working. Once the user logs into my web server using NET::FTP, I ask him to enter his local directory that contains the file he would like to upload, and the remote directory which is the destination where he wants this file to be saved on the server. I have no problem working with the remote information, but I can't seem to work with the user's local information. I am unable to retrieve any local directory information of the user due to the fact that these scripts are running off the web server. Any PWD, CWD, CHDIR that I do retrieves web server information and not local information. Is there any way to retrieve a user's local directory when he's accessing my perl script running on my web server?

I believe my problem is when I'm using the FTP PUT() function. The way I have it currently is:

$ftp->put($file);

I am only specifying the file. Maybe some sort of path is necessary? What do you think I am missing?

Thanks in advance to everyone. It is greatly appreciated.


~Xboxter~
 
Old 05-15-2005, 01:14 AM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
As I understand it, you are trying to use a perl script running as a CGI program on a webserver to upload to the webserver? But you want it to upload via ftp?
 
Old 05-15-2005, 04:26 AM   #3
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
i guess u cant acomplish what u intend with a cgi script. u need loacal perl scripts on the clients in the lan. on a web server u can upload files per http because this is the protocol the server understands and probably there are no ftp-servers running on the clients.
why not http?
 
Old 05-15-2005, 09:09 AM   #4
xboxter
LQ Newbie
 
Registered: May 2005
Posts: 6

Original Poster
Rep: Reputation: 0
Hello Matir, thanks for getting back to me on this.

Yes exactly, I'm trying to use a perl script running as a CGI program on a webserver to upload to the webserver. I'm using FTP via perl's NET::FTP class in order to transfer files from a local machine to the webserver. Both the local machine and webserver are running on a LAN.
However, because this perl script is running on the webserver, I am unable to retrieve any of the user's local directories that he specifies. Is there any way to retrieve local directories from a user who connects to me (the webserver) via FTP?


Hello j-ray, thanks for your reply as well.

There are FTP servers running on the clients and the webserver. How would I accomplish an upload using HTTP? Sorry I'm relatively new at perl and CGI.


Thanks and hope 2 hear from you guys soon.


~Xboxter~
 
Old 05-15-2005, 09:37 AM   #5
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
If there is an FTP server on the clients, you'll need to connect to it and retrieve the file from there.
 
Old 05-15-2005, 01:35 PM   #6
xboxter
LQ Newbie
 
Registered: May 2005
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks Matir. So that would be the only way to do it then?

I was doing some research and came across this:

"In the line where you put the file on the ftp server, the first part should be the file on the client, and the second part should be the name of the file that will be stored on the server."

EX: $ftp->put("/home/test/abc.txt","abc.txt") ;

Do you think that would work or will the first part of the put function still refer to the file on the server?
 
Old 05-15-2005, 01:48 PM   #7
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Assuming that this script is running on the client, that should work fine. Running on the server, that will not work.
 
Old 05-16-2005, 03:10 PM   #8
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
<tr><td><form action='index.php' method='post' name='workimg' enctype='multipart/form-data'>
<input type="file" name="workimg"></td></tr>

<tr><td align='center' colspan='2'><input type="submit" name="submit" value="Upload file"></form>

this is a html form to submit files to a server per http. in this case the processing of the file is handled by a php script.

in perl u will probably be able to retrieve the file as
param("workimg") if u use CGI module and write it somewhere to save it.

if u want to enable the user to specify a directory and a filename u should supply one or 2
<input type='text'>
fields to settle that

hope that helps, cheers j

btw if u install a perl module in most cases there is a detailed documentation available for it typing 'perldoc modulename'

Last edited by j-ray; 05-16-2005 at 03:14 PM.
 
Old 05-16-2005, 06:57 PM   #9
xboxter
LQ Newbie
 
Registered: May 2005
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks Matir and j-ray for your replies. I'm going to use both of your advice to come up with the best solution for my situation. Have a nice day.

~Xboxter~
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Natting a FTP Traffic - urgent please!!!!! raja_lucky22 Linux - Security 1 07-04-2005 06:56 AM
perl and Net::FTP question Tomasfuego Programming 0 12-17-2003 08:13 AM
urgent help needed on ftp proxy Brook Linux - Security 3 08-15-2003 10:40 PM
perl, Net::Ftp, and Novell file modification time neo77777 Programming 0 01-30-2003 09:41 PM
perl NET::FTP binary mode lackluster Programming 5 07-18-2002 06:30 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration