hugsbrugs/php-sftp

There is no license information available for the latest version (1.1) of this package.

PHP SFTP Utilities

1.1 2021-02-11 09:51 UTC

This package is auto-updated.

Last update: 2024-11-11 23:33:12 UTC


README

PHP SFTP Utilities

If you also need FTP : php-ftp

Dependencies :

phpseclib : Github - Documentation - Examples

Install

Install package with composer

composer require hugsbrugs/php-sftp

In your PHP code, load librairy

require_once __DIR__ . '/vendor/autoload.php';
use Hug\Sftp\Sftp as Sftp;

Usage

Test SFTP connection

Sftp::test($server, $user, $password, $port = 22, $timeout = 10);

Check if a file exists on SFTP Server

Sftp::is_file($server, $user, $password, $remote_file, $port = 22, $timeout = 10);

Delete a file on remote FTP server

Sftp::delete($server, $user, $password, $remote_file, $port = 22, $timeout = 10);

Recursively deletes files and folder in given directory (If remote_path ends with a slash delete folder content otherwise delete folder itself)

Sftp::rmdir($server, $user, $password, $remote_path, $port = 22, $timeout = 10);

Recursively copy files and folders on remote SFTP server (If local_path ends with a slash upload folder content otherwise upload folder itself)

Sftp::upload_dir($server, $user, $password, $local_path, $remote_path, $port = 22, $timeout = 10);

Download a file from remote SFTP server

Sftp::download($server, $user, $password, $remote_file, $local_file, $port = 22, $timeout = 10);

Download a directory from remote FTP server (If remote_dir ends with a slash download folder content otherwise download folder itself)

Sftp::download_dir($server, $user, $password, $remote_dir, $local_dir, 
$port = 22, $timeout = 10);

Rename a file on remote SFTP server

Sftp::rename($server, $user, $password, $old_file, $new_file, $port = 22, $timeout = 10);

Create a directory on remote SFTP server

Sftp::mkdir($server, $user, $password, $directory, $port = 22, $timeout = 10);

Create a file on remote SFTP server

Sftp::touch($server, $user, $password, $remote_file, $content, $port = 22, $timeout = 10);

Upload a file on SFTP server

Sftp::upload($server, $user, $password, $local_file, $remote_file = '', $port = 22, $timeout = 10);

List files on SFTP server

Sftp::scandir($server, $user, $password, $path, $port = 22, $timeout = 10);

Get default login SFTP directory aka pwd

Sftp::pwd($server, $user, $password, $port = 22, $timeout = 10);

Tests

Edit example/test.php with your FTP parameters then run

php example/test.php

To Do

PHPUnit Tests

Author

Hugo Maugey visit my website ;)