Welcome to WebmasterWorld Guest from 54.205.170.21

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Automatically Upload File to a Secure Server - CRON Job

HTTPS or FTPS, Curl, PHP, CRON

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



Hi,

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.

Cheers
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 [123.123.123.123...] 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)

WebmasterWorld Administrator incredibill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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)

WebmasterWorld Administrator incredibill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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 !

[blog.dynamichosting.biz...]

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.