Failure to upload with curl in PHP

Viewed 88

I want to use curl in ssh with PHP and I did it, but program sometimes does not work in PHP.

I run this in ssh and it worked successfully:

curl -F video=@123.mp4 "https://example.com"

But when I write this code in PHP it is uploaded it but does not complete:

include('Net/SSH2.php');
$ssh = new Net_SSH2('ip');
if (!$ssh){
    echo 'Error';
} else {
    $ssh->login('username','password') or die("Login failed");
    $ssh->exec('curl -F video=@123.mp4 "https://example.com"');
}

What is the problem?

1 Answers

Use the ssh2 functions. Anything you'd do via an exec() call can be done directly using these functions, saving you a lot of connections and shell invocations.

Example:

$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');

$stream = ssh2_exec($connection, 'curl -F video=@123.mp4 "https://example.com"');

Are you trying to upload the larger file? because PHP might be timed out while uploading the file. I suggest you try with smaller file in few KB, if that works then confirm that code works fine, then you should increase the timeout set_time_limit(0) and run the code

Related