homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Automatically Upload File to a Secure Server - CRON Job

 2:12 pm on Mar 13, 2012 (gmt 0)


I need to:
1) Setup a CRON Job - calls a PHP / Curl script
2) Connect to a Remote Server via HTTPS
3) Upload a File (there is No form)

How can this be done -- using CRON, PHP, and Curl ?

I could also use FTPS if that is better.




 3:12 pm on Mar 13, 2012 (gmt 0)

All of the above.

If there is a script on the other webserver which accepts a file upload, you can POST a file to it using curl

$ch = curl_init();
$fields = "img=@/path/to/image.jpg"
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$result = curl_exec( $ch );
curl_close ($ch);

This will upload a file to the website using the variable name $_FILES['img']

Don't forget you need SSL installed as well as cURL.

If you have this script, you can call it from a cronjob like you suggested.


 4:03 pm on Mar 13, 2012 (gmt 0)

Hi lostdreamer,

Thanks for your reply.

I'm not sure if there is a script on the secure server - I'm checking now.

How would I call the secure URL ? Would $url have the address ?

How does the line: $fields = "img=@/path/to/image.jpg" work ? (unsure of @)

Thanks again.


 6:33 pm on Mar 13, 2012 (gmt 0)

Upload from WHERE?

Is this a server to server thing or a desktop computer to server thing?

If it's just a desktop thing, programs like CuteFTP will do it all, no cron, scripts, nada.

If it's server to server, why mess with PHP? A simple cron to execute a one-line CURL command from a script is simpler to implement than messing with CURL in PHP.


 12:38 am on Mar 14, 2012 (gmt 0)

Thanks incrediBill !

It's a Server A to Server B transfer @ 4:00 PM Monday - Friday (CRON).

And, I have to process daily information in a MySQL Database, plus the Filenames have a Date/Time stamp to uniquely identify them.

Can I send a unique Filename using a CURL command ?

Thanks for the help.


 4:40 am on Mar 14, 2012 (gmt 0)

OK, now that I know it's a report and a transfer, PHP seems perfectly suited for the task.

To answer your question, cURL can send a unique filename, but you need to create the unique file name you pass to cURL.


 1:20 pm on Mar 14, 2012 (gmt 0)

Got it -- thanks !

As another option, I did find info on installing SSH2 Extension for PHP on CentOS 5 and it worked !


I'll be using PHP's ssh2 commands unless I hit a brick wall and need to re-visit CURL.

Thanks again for your help.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved