Your IP : 216.73.216.48
<?php
namespace app\models\access;
use Yii;
class SftpAccess {
public function checkConnection($host, $port, $username, $password) {
$connection = @ssh2_connect($host, $port);
@ssh2_auth_password($connection, $username, $password);
$sftp = @ssh2_sftp($connection);
if ($sftp) {
return true;
}
return false;
}
public function editFileContent($serverDetails, $filePath, $content) {
$fileWrapper = 'ssh2.sftp://' . $serverDetails->username . ':' . $serverDetails->password . '@' . $serverDetails->host . ':' . $serverDetails->port . '/' . $serverDetails->dir . '/' . $filePath;
$options = array('ftp' => array('overwrite' => true));
$stream = stream_context_create($options);
if (file_put_contents($fileWrapper, $content, 0, $stream)) {
return true;
}
return false;
}
}