PHP code example of coercive / sftp

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

    

coercive / sftp example snippets


use Coercive\Utility\SFTP\SFTP;

$SFtp = new SFTP('127.0 0.1', 22);
$SFtp->login('BestUser', 'BestPassword');
$SFtp->connect();

$SFtp->disconnect();

$SFtp->mkdir('/example/dir/test');

$data = $SFtp->list('/example/dir/test');

$SFtp->upload('/README.md', '/example/dir/test/test.md');

$SFtp->download('/example/dir/test/test.md', '/test/dowloaded_file.md');

$SFtp->setTmpPrefix('_test_tmp_prefix_');
$SFtp->download('/example/dir/test/test.md', $filepath);

# do something with your file
rename($filepath, '/test/dowloaded_file.md');

$integer = $SFtp->filesize('/example/dir/test/test.md');

$data = $SFtp->read('/example/dir/test/test.md');

$SFtp->write('/example/dir/test/test.md', "# Hello World !\n");

$SFtp->delete('/example/dir/test/test.md');