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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.