Jump to content

PHP FTP


me102

Recommended Posts

Hello I am having a little bit of a problem when I try to upload a directory and its subdirectorys i keep getting errors because the done exist but how would I go about making them,

 

This is what I have,

 

<?php
      
      

    
    //Source Files, Where to put them
    $src_dir = "/source_codes/";
    $dst_dir = "/haha/";
    
    // Start the ftp connection 
    $conn_id = ftp_connect($ftp_server) or die("<span style='color:#FF0000'><h2>Couldn't connect to $ftp_server</h2></span>");  
    $login_result = ftp_login($conn_id, $user, $passwd); 
  
     // check connection
     if ((!$conn_id) || (!$login_result)) {
          echo "FTP connection has failed!";
          echo "Attempted to connect to $ftp_server for user $ftp_user_name";
          die;
     } else {
          echo "<br>Connected to $ftp_server, for user $user<br>";
     }
     
     
     
    function ftp_copy($src_dir, $dst_dir) {
     global $conn_id;

    $d = dir($src_dir);

    while($file = $d->read()) {
        if ($file != "." && $file != "..") {
            if (is_dir($src_dir."/".$file)) {
                
                if (!@ftp_chdir($conn_id, $dst_dir."/".$file)) {
                    ftp_mkdir($conn_id, $dst_dir."/".$file);
                }

                  ftp_copy($src_dir."/".$file, $dst_dir."/".$file);
                  
            }else {

            $upload = ftp_put($conn_id, $dst_dir."/".$file, $src_dir."/".$file, FTP_BINARY);
            
             // check upload status
             if (!$upload) {
                 echo "FTP upload has failed!";
             } else {
                 echo "Uploaded $source_file to $ftp_server as $destination_file";
             }

            }
        }
    }

$d->close();
}

     

ftp_copy($src_dir, $dst_dir);


// close the FTP stream
ftp_close($conn_id);
?>



Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.