coercive/sftp

0.0.0 2023-04-24 17:04 UTC

This package is auto-updated.

Last update: 2024-04-24 19:11:00 UTC


README

SFTP utility for PHP

Get

composer require coercive/sftp

Dependencies

This package use ext-ssh2 : manual

Usage

Connect to FTP

use Coercive\Utility\SFTP\SFTP;

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

Disconnect

$SFtp->disconnect();

Create directory

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

List diretories and files

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

Upload file

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

Download file

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

Download file : with auto tmp name and prefix

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

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

Filesize

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

Read file

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

Write into file

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

Remove file

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