#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    57
    Rep Power
    12

    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?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    8
    Rep Power
    0
    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

    $ftp->put($sourcefile,$targetfile);
    /edit

    BTW: Check this site for more Net:FTP options:
    http://www.perldoc.com/perl5.8.0/lib/Net/FTP.html
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    57
    Rep Power
    12
    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?

    PHP Code:

    #!/usr/bin/perl -w
    use Net::FTP;
    use 
    CGI::Carp qw(fatalsToBrowser warningsToBrowser);

    $home="serva.com";
    $username="self";
    $password="pA88w0Rd";
    $directory="/home/users/serva/public_html";
    $filename="faq.htm";


    $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";
    $ftp->quit
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    8
    Rep Power
    0
    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
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    57
    Rep Power
    12
    Thanks once again for getting back to me.

    I have just resolved the issue:
    $directory="/home/users/serva/public_html";
    did not require a path - I altered the line to:
    $directory="public_html";
    and the script moved on to die at 'Couldn't get faq.htm'
    I checked:
    $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!
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    8
    Rep Power
    0
    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
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    57
    Rep Power
    12
    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.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    8
    Rep Power
    0
    No problem

IMN logo majestic logo threadwatch logo seochat tools logo