PHP code example of buuum / ftp

1. Go to this page and download the library: Download buuum/ftp 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/ */

    

buuum / ftp example snippets


$host = 'my__host';
$username = 'my_username';
$password = 'my_pass';

$connection = new Connection($host, $username, $password);
//$connection = new AnonymousConnection($host);
//$connection = new SSLConnection($host, $username, $password);
try {
    $connection->open();
} catch (\Exception $e) {
    echo $e->getMessage();
}

$ftp = new FtpWrapper($connection);

$connection->close();

$localFile = 'demofile.txt';
$remoteFile = 'folder/demofile.txt'
$ftp->get($localFile, $remoteFile);

$ftp->put($remoteFile, $localFile);

$path = 'folder/subfolder1/subfolder2';
$ftp->makedir($path);

$path = 'folder';
$ftp->removedir($path);

$list = $ftp->nlist($path);

array(7) {
  [0]=>
  string(1) "."
  [1]=>
  string(2) ".."
  [2]=>
  string(4) "demo"
  [3]=>
  string(9) "demo1.txt"
  [4]=>
  string(9) "demo2.txt"
  [5]=>
  string(7) "folder"
}

$list = $ftp->rawlist($path, $recursive);

array(48) {
  [0]=>
  string(63) "drwxr-xr-x    4 user      user            4096 May 12 05:53 ."
  [1]=>
  string(64) "drwxr-xr-x    4 user      user            4096 May 12 05:53 .."
  [2]=>
  string(66) "drwxr-xr-x    2 user      user            4096 May 12 05:56 demo"
  [3]=>
  string(71) "-rw-r--r--    1 user      user            1544 May 12 05:07 demo1.txt"
  [4]=>
  string(71) "-rw-r--r--    1 user      user            1544 May 12 05:07 demo2.txt"
  [5]=>
  string(69) "drwxr-xr-x    3 user      user            4096 May 12 05:07 folder"
  [6]=>
  string(0) ""
  ....

$oldname = 'folder/subfolder/filetochange.txt';
$newname = 'folder/subfolder/filechange.txt';
$ftp->rename($oldname, $newname);

$path_file = 'folder/subfolder/filechange.txt';
$ftp->delete($path_file);