First of all, I'm very new to php, so bear with me. I'm wondering if I can upload a file that I have on my desktop to a remote SHH server using php. I have the ip address, port number, username, and password if that helps, but have no clue as to how to approach this problem. I read that using an html post only allows you to upload files to a local server, not a remote one. Any ideas?
Phpseclib has a class based interface for interacting with SFTP.
For example:
require __DIR__ . '/vendor/autoload.php';
use phpseclib\Net\SFTP;
$sftp = new SFTP('www.domain.tld');
if (!$sftp->login('username', 'password')) {
exit('Login Failed');
}
// puts a three-byte file named filename.remote on the SFTP server
$sftp->put('filename.remote', 'xxx');
// puts an x-byte file named filename.remote on the SFTP server,
// where x is the size of filename.local
$sftp->put('filename.remote', 'filename.local', SFTP::SOURCE_LOCAL_FILE);
SFTP documentation: http://phpseclib.sourceforge.net/sftp/intro.html
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.