July 6, 2021 . 2 MIN READ
http://www.webhostingtalk.com/showthread.php?t=418793
http://www.webhostingtalk.com/showthread.php?t=418793
https://www.codexpedia.com/php/php-ssh2-upload-and-download-files-through-sftp/
You can upload your site files after zip, via scp also
scp local_site.zip runcloud@server-ip-address:webapps/your-web-app-path/
<?php
/**
* Simple code for executing commands on a remote Linux server via SSH in PHP
*
* @author Phil Kershaw (In collaboration with Philip Mott)
*
* Note: ssh2_connect requires libssh2-php which is a non-standard PHP lib.
* Debian: apt-get install libssh2-php
* Redhat: yum install libssh2-php ???? I’ve no idea for redhat, sorry.
*/
/*
$server = “50.116.51.202”; // server IP/hostname of the SSH server
$username = ‘root’; // username for the user you are connecting as on the SSH server
$password = ‘password!’; // password for the user you are connecting as on the SSH server
$runcloud_command= ‘https://manage.runcloud.io/script/installer/aq4bIlLelEbaZmzmGFmui6VHx91554870993NCD0qghDdPyLh0U4Yr0rIKsqgUFdgKn4gfemsmxGaiAiyG6Oo0G3dFIgBBV1VA6G/JY8g4IRL6s6mQZPwjGo5wmNFvVSdTsXauy0EA3P6PREpuuropE466tl26Ud7fna6N4mIrxlfp7iMHTWCIVAHiWMLj1z1sYVvfUIow6FUuLMA80qUUQyiUTHdjrYLv4gC’;
$command = ‘export DEBIAN_FRONTEND=noninteractive; echo \’Acquire::ForceIPv4 “true”;\’ | tee /etc/apt/apt.conf.d/99force-ipv4; apt-get update; apt-get install curl netcat-openbsd -y; apt-get -o Dpkg::Options::=”–force-confdef” -o Dpkg::Options::=”–force-confold” upgrade -y; curl –silent –location ‘. $runcloud_command .’ | bash -; export DEBIAN_FRONTEND=newt’; // could be anything available on the server you are SSH’ing to
// Establish a connection to the SSH Server. Port is the second param.
$connection = ssh2_connect(‘50.116.51.202′, 22);
ssh2_auth_password($connection, $username,$password );
$stream = ssh2_exec($connection, $command );
// Sets blocking mode on the stream
stream_set_blocking($stream, true);
// Get the response of the executed command in a human readable form
$output = stream_get_contents($stream);
// echo output
echo “<pre>{$output}</pre>”;
*/
$localFile=’/home/runcloud/webapps/app-midas-prosite/secure-file-upload/php1.zip’;
$remoteFile=’/home/runcloud/webapps/insiderstorybulletinapp/public/php1.zip’;
$host = “50.116.51.202”;
$port = 22;
$user = “runcloud”;
$pass = “password”;
$connection = ssh2_connect($host, $port);
ssh2_auth_password($connection, $user, $pass);
$sftp = ssh2_sftp($connection);
$stream = fopen(“ssh2.sftp://$sftp$remoteFile”, ‘w’);
$file = file_get_contents($localFile);
fwrite($stream, $file);
fclose($stream);
// unzip
//unzip -d /home/$new_user/ -oq /root/files/valve.zip
$connection = ssh2_connect($host, $port);
ssh2_auth_password($connection, $user, $pass);
$command = ‘unzip -d /home/runcloud/webapps/insiderstorybulletinapp/public/ -oq /home/runcloud/webapps/insiderstorybulletinapp/public/php1.zip’;
$stream = ssh2_exec($connection, $command );
// Sets blocking mode on the stream
stream_set_blocking($stream, true);
// Get the response of the executed command in a human readable form
$output = stream_get_contents($stream);
// echo output
echo “<pre>{$output}</pre>”;