gonzalo123/ftplib

Ftp helper

Installs: 13

Dependents: 0

Stars: 6

Watchers: 3

Forks: 1

Language: PHP

dev-master 2013-05-13 13:31 UTC

README

Build Status

<?php
include __DIR__ . "/../vendor/autoload.php";

use FtpLib\Ftp,
    FtpLib\File;

list($host, $user, $pass) = include __DIR__ . "/credentials.php";

$ftp = new Ftp($host, $user, $pass);
$ftp->connect();
$ftp->setPasv();

$file = $ftp->putFileFromPath(__DIR__ . '/fixtures/foo');
echo $file->getName();
echo $file->getContent();
$file->delete();

$file = $ftp->putFileFromString('bar', 'bla, bla, bla');
echo $file->getName();
echo $file->getContent();
$file->delete();

$ftp->mkdir('directory')->chdir('directory')->putFileFromString('newFile', 'bla, bla')->delete();
$ftp->rmdir('directory');

$ftp->putFileFromString('file1', 'bla, bla, bla');
$ftp->putFileFromString('file2', 'bla, bla, bla');

$ftp->getFiles(function (File $file) use ($ftp) {
    switch($file->getName()) {
        case 'file1':
            $file->delete();
            break;
        case 'file2':
            $ftp->mkdir('backup')->chdir('backup')->putFileFromString($file->getName(), $file->getContent());
            break;
    }
});

FTP over ssl is also availabel with Ftp::connectSSL() instead Ftp::connect():

<?php
$ftp = new Ftp($host, $user, $pass);
$ftp->connectSSL();