PHP code example of lazzard / ftp-bridge

1. Go to this page and download the library: Download lazzard/ftp-bridge library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lazzard / ftp-bridge example snippets




azzard\FtpBridge\Logger\ArrayLogger;
use Lazzard\FtpBridge\Logger\LogLevel;
use Lazzard\FtpBridge\FtpBridge;

try {
    // Logger is optional
    $logger = new ArrayLogger;

    // set log levels prefixes
    LogLevel::setInfo('<--');
    LogLevel::setError('<--');
    LogLevel::setCommand('-->');

    // create bridge instance
    $ftp = new FtpBridge($logger);

    $hostname = '[email protected]';
    $username = 'username';
    $password = 'password';

    if ($ftp->connect($hostname, 21)) {
        // connected
        if ($ftp->login($username, $password)) {
            // logged

            $ftp->send("PWD");
            $ftp->receive();

            // open a passive data connection
            if ($ftp->openPassive()) {
                $ftp->send("NLST .");
                $ftp->receive();

                $ftp->receiveData();
                $ftp->receive();
            }
        }

        $ftp->send("QUIT");
        $ftp->receive();
    }

    print_r($logger->getLogs());
    
} catch (Exception $ex) {
    print_r($ex->getMessage();
}