1

I need to upload a file to my FTP server using cURL. let me explain better.

I have this URL http://www.server.com/file.zip and I need to copy the "file.zip" to a FTP server without having to download it to my PC.

I have seen some examples that use cURL to upload files but are they are my hard drive and I need is upload from a URL.

Thank you for your help.

1
  • You need this command. Commented Sep 9, 2012 at 3:52

2 Answers 2

1

Since you don't know if you're saving it properly, just use the stream.

<?php

// open some file for reading
$file = 'http://server.com/file.zip';
$fp = fopen($file, 'r');

// 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);

// try to upload $file
if (ftp_fput($conn_id, $file, $fp, FTP_ASCII)) {
    echo "Successfully uploaded $file\n";
} else {
    echo "There was a problem while uploading $file\n";
}

// close the connection and the file handler
ftp_close($conn_id);
fclose($fp);

?>

By the way, I'm just using PHP Manual examples for these answers. You should, too. Look here.

Sign up to request clarification or add additional context in comments.

9 Comments

I get this error "There was a problem while uploading Resource id #3"
You either have an FTP problem, or the file wasn't actually downloaded to the server because of permissions. Used chmod to fix the latter.
I check the information of the FTP and change the permissions to 777, but I still get the same error.
Check to see if the file was downloaded, first
I'm sorry but I do not know how to check if the file was downloaded. thanks for the help, I'll keep trying.
|
-1

i know its abit late but for anyone who needs this i spent hours looking for something similar
http://bgallz.org/1345/php-upload-multiple-files-url/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.