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

    Join Date
    Feb 2002
    Location
    Ireland
    Posts
    170
    Rep Power
    13

    uploading a file to more than one server: useing PHP's FTP function


    Hi,

    I want to make a quick little app to save time for something I have to do in work. I frequently have to upload a latest.gif to 4 different web servers using FTP programs. This is quite annoying so I decided I am going to try to make a PHP script that will upload the file to all 4 web servers at once from one form field and 1 submit button.

    Does anyone know how I would do this?

    The servers are all duplicated of each other and have the same password and username as well as paths etc.

    It would be very handy if I could put this together and would be one less monotonous task for me to do every day.

    Thanks in advance,
    Martin

    PS: This doesnt need to be too advanced, it just needs to upload the image to the 4 servers and to confirm that the upload worked.
  2. #2
  3. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    793
    Just make a loop that goes through each address to upload to and repeat the ftp upload to each one.
    Something like this: (this is untested, written on the fly)
    PHP Code:
    $addr = array('ftp_address1','ftp_address2');
    $ftp_user 'your_user_id';
    $ftp_pass 'your_pass';
    $path_to_upload '/some/path';
    $filename '/path/to/your_file_to_upload.txt';
    foreach(
    $addr as $ftp_adr) {
        
    $con=ftp_connect($ftp_art) or die('Unable to connect to ftp location.');
        
    ftp_login($con,$ftp_user,$ftp_pass) or die('Failed to logon as '.$ftp_user);
        
    ftp_chdir($con,$path_to_upload);
        
    ftp_put($con,$filename,$filename,FTP_BINARY) or die('Failed to upload file.');
        
    ftp_close($con);

  4. #3
  5. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,648
    Rep Power
    4493
    What do you have so far? There are examples in the manual and it's about the same as fopen(), fwrite(), etc...

    PHP Code:
    $server = array('ip1','ip2','ip3','ip4');
    foreach(
    $server as $ip)
    {
      
    $cid ftp_connect($ip);
      
    ftp_login($cid,$user,$password);
      
    ftp_put($cid$dest$sourceFTP_BINARY);
      
    ftp_close($cid);

    ---John Holmes...
    -- Cigars, whiskey and wild, wild women. --

IMN logo majestic logo threadwatch logo seochat tools logo