Link to home
Start Free TrialLog in
Avatar of bogdan300
bogdan300

asked on

Upload a tar file to a ftp server

Hi,

I need some help from you guys.
I need to create a php script to upload a tar file to a ftp server.
The tar file is located at www.site.com/file.tar and I want it uploaded to ftp.mysite.com to directory public_html/files/

This is extremely urgent.
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

This is a typical upload routine:

// set up basic connection
$conn_id = ftp_connect($ftp_server);


// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// check connection
if ((!$conn_id) || (!$login_result)) {
        echo "FTP connection has failed!";
        echo "Attempted to connect to $ftp_server for user $ftp_user_name";
        exit;
    } else {
          echo '<br><br>';
        echo "Connected to $ftp_server, for user $ftp_user_name";
    }
     
$ftp_dir = ftp_pwd($conn_id);
$destination_file = $ftp_dir.$sourcefile_name;
echo "<br>$destination_file";

// upload the file
$upload = ftp_put($conn_id, $destination_file, $sourcefile, FTP_BINARY);

// check upload status
if (!$upload) {
        echo "<br><br>FTP upload has failed!";
    } else {
        echo "<br><br>Uploaded $sourcefile_fix to $ftp_server as $destination_file";
    }

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

You will need to have downloaded your file previously with filename described by $sourcefile
Avatar of bogdan300
bogdan300

ASKER

Yes I seen this example on php.net, but I am not able to make it upload.
Please give me more detailed help with an example.
ASKER CERTIFIED SOLUTION
Avatar of Marcus Bointon
Marcus Bointon
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial