How to upload a file to directadmin using curl function?

Mohammad_J

New member
Joined
Jul 5, 2017
Messages
1
I have a script to upload myfile.zip to my directadmin user public_html directory for example.

In my previous server it was working fine. But after migrating to my new server and also update directadmin at the same time it is not working any more. what's the problem?

any help? Thank You

Code:
$cookie_jar = tempnam('/tmp','cookie');

$post = array(
    'referer'=>'',
    'username'=>$user_name,
    'password'=>$user_pass,
);
$c = curl_init("http://$server:$serverport/CMD_LOGIN");
curl_setopt($c, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, $post);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_jar);
$page = curl_exec($c);
curl_close($c);

$file = (dirname(__FILE__).'/assets/myfile.zip');
$post = array(
    'action'=>'upload',
    'path'  =>  "/domains/example.com/public_html",
    'file1' => new CurlFile($file, 'application/download', 'myfile.zip'),
);

$c = curl_init("http://$server:$serverport/CMD_FILE_MANAGER");
curl_setopt($c, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($c, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, $post);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_jar);
curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_jar);
$page = curl_exec($c);
curl_close($c);
 
Back
Top