FTPClient for PHP

1.0 2013-11-27 01:25 UTC


Build Status Total Downloads Latest Stable Version

Support via Gittip

By Melih Ucar. (

licensed under the MIT licenses


Connection to FTP Host :

$ftp = new FTPClient();
$ftp->connect($host, $ssl, $port, $timeout);
$ftp->login($username, $password);

Using Passive Mode :

// This uses passive mode

// If you want to disable using passive mode then

Using Binary Mode :

// This uses binary mode, required for downloading binaries like zip

// standard is false

Changing Directory :

// You can use fullpath to change dir

// or you can use method chaining

Change To Parent Directory :


$ftp->parentDirectory(); // now we are in /root_dir

Getting Current Directory :

// will return current path as string

Creating Directory :

// creates a directory in current path

Removing Directory :


Getting Directory List :

// returns directory list as array

Getting Directory List :

// executes the FTP LIST command, and returns the result as an array
$ftp->rawlistDirectory($parameters, $recursive);

Deleting File :


Returns file size (bytes) :


Returns last modified time :

// returns unix timestamp

// returns formated
$ftp->modifiedTime($filename, $format);

Renaming files or folders :

$ftp->rename($current, $new);

Downloading a file :

// Downloads a file from remote host
$ftp->get($localFile, $remoteFile);

// Downloads file to an open file
$ftp->fget($handle, $remoteFile);

Uploading a file :

// Uploading local file to remote host
$ftp->put($remoteFile, $localFile);

// Uploading from an open file
$ftp->fput($remoteFile, $handle);

Getting server options :


Setting server options :

$ftp->setOption(FTPClient::TIMEOUT_SEC, 30);

Allocating space for uploading file :


Changing file and directory permissions :

$ftp->chmod($mode, $filename);

Running custom command on remote server :


Error Handling :

Class throws exception if opetarion fails. So simply use try-catch blocks.

try {
    $ftp = new FTPClient();
    $ftp->connect($host, $ssl, $port, $timeout);
    $ftp->loginlogin($username, $password);
} catch (Exception $e) {
    // we got the error!


Did you find a bug or do you know a better way to do it? Simply just fork and fix it. Then send a pull request.