php-core / sftp
PHP SFTP Utilities
Requires
- php: >=8.1
- phpseclib/phpseclib: 3.0.39
This package is auto-updated.
Last update: 2024-09-06 00:36:58 UTC
README
PHP SFTP Utilities (PHP >= 8.1)
Based on: php-sftp
Dependencies :
phpseclib : Github - Documentation - Examples
Install
Install package with composer
composer require php-core/sftp
In your PHP code, load library
require_once __DIR__ . '/vendor/autoload.php'; use PHPCore\SFTP\SFTP;
Usage
Test SFTP connection
SFTP::test($server, $user, $password, $port = 22, $timeout = 10);
Check if a file exists on SFTP Server
SFTP::isFile($server, $user, $password, $remoteFile, $port = 22, $timeout = 10);
Delete a file on remote FTP server
SFTP::delete($server, $user, $password, $remoteFile, $port = 22, $timeout = 10);
Recursively deletes files and folder in given directory (If remotePath ends with a slash delete folder content otherwise delete folder itself)
SFTP::rmdir($server, $user, $password, $remotePath, $port = 22, $timeout = 10);
Recursively copy files and folders on remote SFTP server (If localPath ends with a slash upload folder content otherwise upload folder itself)
SFTP::uploadDir($server, $user, $password, $localPath, $remotePath, $port = 22, $timeout = 10);
Download a file from remote SFTP server
SFTP::download($server, $user, $password, $remoteFile, $localFile, $port = 22, $timeout = 10);
Download a directory from remote FTP server (If remoteDir ends with a slash download folder content otherwise download folder itself)
SFTP::downloadDir($server, $user, $password, $remoteDir, $localDir, $port = 22, $timeout = 10);
Rename a file on remote SFTP server
SFTP::rename($server, $user, $password, $oldFile, $newFile, $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, $remoteFile, $content, $port = 22, $timeout = 10);
Upload a file on SFTP server
SFTP::upload($server, $user, $password, $localFile, $remoteFile = '', $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
License
MIT