Git Product home page Git Product logo

ftpclient's Introduction

FTP Client for PHP

Build Status Total Downloads Latest Stable Version

Support via Gittip

By Melih Ucar. (http://www.melihucar.net/)

licensed under the MIT licenses

USAGE

Connection to FTP Host :

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

Using Passive Mode :###

// This uses passive mode
$ftp->passive();

// If you want to disable using passive mode then
$ftp->passive(false);

Using Binary Mode :###

// This uses binary mode, required for downloading binaries like zip
$ftp->binary(true);

// standard is false

###Changing Directory :###

// You can use fullpath to change dir
$ftp->changeDirectory('/root_dir/sub_dir');

// or you can use method chaining
$ftp->changeDirectory('/root_dir')->changeDirectory('sub_dir');

###Change To Parent Directory :###

$ftp->changeDirectory('/root_dir/sub_dir');

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

###Getting Current Directory :###

// will return current path as string
$ftp->getDirectory();

###Creating Directory :###

// creates a directory in current path
$ftp->createDirectory($directoryName);

###Removing Directory :###

$ftp->removeDirectory($directoryName);

###Getting Directory List :###

// returns directory list as array
$ftp->listDirectory();

###Getting Directory List :###

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

###Deleting File :###

$ftp->delete($filename);

###Returns file size (bytes) :###

$ftp->size($filename);

###Returns last modified time :###

// returns unix timestamp
$ftp->modifiedTime($filename);

// 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 :###

$ftp->getOption(FTPClient::TIMEOUT_SEC);

###Setting server options :###

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

###Allocating space for uploading file :###

$ftp->allocate($filesize);

###Changing file and directory permissions :###

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

###Running custom command on remote server :###

$ftp->exec($command);

###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!
}

Contributing

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.