PHP code example of cxxi / ftp-client
1. Go to this page and download the library: Download cxxi/ftp-client 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/ */
cxxi / ftp-client example snippets
$clientFtp = FtpClient::fromUrl('ftp://user:[email protected] :21/path');
$clientFtps = FtpClient::fromUrl('ftps://user:[email protected] :21/path');
$clientSftp = FtpClient::fromUrl('sftp://user:[email protected] :22/path');
use Cxxi\FtpClient\FtpClient;
$client = FtpClient::fromUrl('ftp://user:[email protected] :21/path');
$client
->connect()
->loginWithPassword()
->listFiles('.');
use Cxxi\FtpClient\Model\ConnectionOptions;
$options = new ConnectionOptions(
timeout: 15,
retryMax: 3,
retryDelayMs: 500,
retryBackoff: 2.0,
retryJitter: true
);
$client = FtpClient::fromUrl(
'ftps://user:[email protected] :21/path',
options: $options
);
$options = ConnectionOptions::fromArray([
'timeout' => 15,
'passive' => 'auto',
'retry' => [
'max' => 3,
'delay_ms' => 500,
'backoff' => 2.0,
'jitter' => true,
'unsafe_operations' => false,
],
'ssh' => [
'host_key_algo' => 'ssh-ed25519',
'expected_fingerprint' => 'MD5:aa:bb:cc:dd:...',
'strict_host_key_checking' => true,
],
]);
$options = new ConnectionOptions(
hostKeyAlgo: 'ssh-ed25519',
expectedFingerprint: 'MD5:aa:bb:cc:dd:...',
strictHostKeyChecking: true
);
$options = new ConnectionOptions(
retryMax: 3,
retryUnsafeOperations: true
);
$client->putFile('remote.csv', '/local/file.csv');
$client->downloadFile('remote.csv', '/tmp/remote.csv');
$client->isDirectory('subdir');
$client->makeDirectory('subdir', recursive: true);
$client->removeDirectory('empty-dir');
$client->removeDirectoryRecursive('dir-to-delete');
$client->deleteFile('old.csv');
$client->rename('old.csv', 'new.csv');
$size = $client->getSize('file.csv');
$mtime = $client->getMTime('file.csv');
$client->chmod('file.csv', 0644);
$raw = $client->rawList('.', recursive: false);
$mlsd = $client->mlsd('.');
$client
->connect()
->loginWithPassword();
$client->loginWithPassword('user', 'pass');
$client
->connect()
->loginWithPubkey(
'/home/me/.ssh/id_rsa.pub',
'/home/me/.ssh/id_rsa',
user: 'my-user'
);
use Cxxi\FtpClient\FtpClient;
$client = FtpClient::fromUrl(
'ftp://user:[email protected] :21/path',
logger: $logger
);
$client->closeConnection();
text
ftp://user:pass@host:21/path
ftps://user:pass@host:21/path
sftp://user:pass@host:22/path