August 13th, 2002, 12:17 AM
Net::FTP and 'one click' file transfer
I have been trying to understand the Net::FTP module with regard to a particular system I am trying to put into place.
I would like to be able to transfer a file from my server to another server by clicking a send button or link in my browser. Thus the server information (username, password etc) to where I am sending would be kept in a file or database on my server and the send button would create a connection between the servers, transfer the file and then disconnect.
However Net::FTP seems to require a command line input which would impair the desired 'one click' transfer I am looking for.
Is it possible to create a system like the one I describe using Net::FTP or other module, or am I flogging a dead horse?
August 13th, 2002, 07:12 AM
So you've got 2 servers (server A and server B). Server A contains a file that should be sent to server B.
This transfer should start when you click the button in your browser. The script that sends the file from A to B resides on server A.
I don't see a real problem here. If you store all the required information (hostname,user,password,sourcefile, targetfile) on server A, the script on server A could connect to server B and send the file, as soon as you click the button in your browser.
The command line input is just the commands that are needed to transfer the file from A to B, something like
BTW: Check this site for more Net:FTP options:
August 13th, 2002, 04:13 PM
Thanks d0g1e for replying - you have given me the confidence to keep trying!
Assimilating all the info I have read I have the following assuptions and a script (these may be way off base but I feel I am getting close(r)!)
Remember my script is on ServerA and I am moving a file from Server A (serva) to Server B (servb). My assumption is that I have to call up and get the script from serva and then operate a sub routine to put the file on servb.
So far I am trying to get the file but I am getting the error message: 'couldn't change directory' (die message line 11). I wonder if anyone could check it and see if I have a problem there, or any other reason why the directory might not change?
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
$ftp = Net::FTP->new("$home") or die "Can't connect: $@\n";
$ftp->login($username, $password) or die "Couldn't login\n";
$ftp->cwd($directory) or die "Couldn't change directory\n";
$ftp->get($filename) or die "Couldn't get $filename\n";
#$ftp->put($filename) or die "Couldn't put $filename\n";
August 13th, 2002, 04:33 PM
The code looks fine.. (I can't try it at the moment)
Have you tried executing those commands by hand (using a ftp client?) How about adding a trailing / (slash) to the directory
August 13th, 2002, 05:05 PM
Thanks once again for getting back to me.
I have just resolved the issue:
did not require a path - I altered the line to:
and the script moved on to die at 'Couldn't get faq.htm'
$filename="faq.htm"; and found it to be "faq.html".
I corrected it and the script went straight to Error 500. I assume that there's no problem with any of the steps so far but I need to go ahead and finish it!
August 13th, 2002, 05:23 PM
Strange.. absolute paths are supposed to work with ftp. Did the user have insufficient permissions?
anyway, add some http headers and you should be done! (I guess) have fun
August 14th, 2002, 03:12 AM
Well, after a certain amount of fiddling around I got the script transferring server to server - I really appreciate your help. In the end it was straightforward but more of a confidence thing so you support was really useful.
As a postscript I tried using the /path/ of servb for the upload and that was not accepted either - a simple directory name was all that was required (both sites are operated by the same ISP - though on different servers). I may pose the question to the ISP if I get the time. Thanks once again.
August 14th, 2002, 07:45 AM