PHP Classes

PHP SSH2 SFTP Client: Transfer files and run commands with SFTP and SSH

Recommend this page to a friend!
  Info   View files Documentation   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 226 All time: 8,176 This week: 117Up
Version License PHP version Categories
php-ssh2-sftp-client 1.0.0The PHP License5Networking, PHP 5, Files and Folders


This package can transfer files and run commands with SFTP and SSH.

It can connect to SSH server and perform operations necessary to execute file transfer operations like creating, listing, renaming and deleting directories, uploading, downloading, renaming, deleting, get status information of files, and creating symbolic links.

The package can also connect to a SSH server and execute given commands.

Picture of Suxumi
Name: Suxumi <contact>
Classes: 1 package by
Country: Georgia Georgia
Age: ???
All time rank: 40577 in Georgia Georgia
Week rank: 683 Up2 in Georgia Georgia Up



PHP Sftp Client Class using SSH2 functions and shell commands, with server-side error handlings



Copyright (c) 2015 GR<br> licensed under the MIT licenses<br>


Connect to an SSH server & authenticate:
// initialize
$sftp = new \GR\SftpClient();

// connect
$sftp->connect($host, $port, $timeout);

// login
$sftp->login($user, $pass);

Get current directory:

Create directory
$sftp->createDirectory($path, $ignore_if_exists);

Delete directory

Delete file

Get directory content list
// just names
$sftp->getDirectoryList($path, $recursive);

// rawlist
$sftp->getDirectoryRawList($path, $recursive);

// <b>formated</b> rawlist
$sftp->getDirectoryRawListFormatted($path, $recursive);

Get file stat
$stat = $sftp->stat($path); 

Download a file
$sftp->downloadFile($remote_file, $local_file); 

Upload a file
$sftp->uploadFile($local_file, $remote_file[, int $create_mode = 0644 ] ); 

Rename file/directory
// Rename File
$sftp->renameFile($oldname, $newname);

// Rename Folder
$sftp->renameDirectory($oldname, $newname);

// both of them are alias of
$sftp->renameFileOrFolder($oldname, $newname);

Create Symlink
$sftp->createSymlink($target, $link); 

Execute custom command

Close connection

Handle Errors

try {
	$sftp = new \GR\SftpClient();
	$sftp->connect($host, $port, $timeout);
	$sftp->login($user, $pass);
catch(ErrorException $e) {
	// handle the error

  Files folder image Files  
File Role Description
Accessible without login Plain text file Doc. Documentation
Plain text file SftpClient.class.php Class Class source

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:8,176
This week:117Up