PHP Sftp Client Class using SSH2 functions and shell commands, with server-side error handlings
By GR admin@admin.ge
Copyright (c) 2015 GR
licensed under the MIT licenses
http://www.opensource.org/licenses/mit-license.html
<?php
// initialize
$sftp = new \GR\SftpClient();
// connect
$sftp->connect($host, $port, $timeout);
// login
$sftp->login($user, $pass);
<?php
$sftp->getCurrentDirectory();
<?php
$sftp->createDirectory($path, $ignore_if_exists);
<?php
$sftp->deleteDirectory($path);
<?php
$sftp->deleteFile($path);
<?php
// just names
$sftp->getDirectoryList($path, $recursive);
// rawlist
$sftp->getDirectoryRawList($path, $recursive);
// <b>formated</b> rawlist
$sftp->getDirectoryRawListFormatted($path, $recursive);
<?php
$stat = $sftp->stat($path);
<?php
$sftp->downloadFile($remote_file, $local_file);
<?php
$sftp->uploadFile($local_file, $remote_file[, int $create_mode = 0644 ] );
<?php
// Rename File
$sftp->renameFile($oldname, $newname);
// Rename Folder
$sftp->renameDirectory($oldname, $newname);
// both of them are alias of
$sftp->renameFileOrFolder($oldname, $newname);
<?php
$sftp->createSymlink($target, $link);
<?php
$sftp->ssh2_exec($cmd);
<?php
$sftp->close();
<?php
try {
$sftp = new \GR\SftpClient();
$sftp->connect($host, $port, $timeout);
$sftp->login($user, $pass);
}
catch(ErrorException $e) {
// handle the error
}