-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8a462fc
Showing
8 changed files
with
1,353 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
TODO.txt | ||
vendor/* | ||
build/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "hugsbrugs/php-ftp", | ||
"description": "PHP FTP Utilities", | ||
"authors": [ | ||
{ | ||
"name": "Hugo Maugey", | ||
"email": "[email protected]", | ||
"homepage": "https://hugo.maugey.fr", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"hugsbrugs/php-string": "^1.0" | ||
}, | ||
"autoload":{ | ||
"psr-4": {"Hug\\": "src/Hug/"} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
<?php | ||
|
||
ini_set('display_errors', 1); | ||
ini_set('error_reporting', E_ALL); | ||
ini_set('max_execution_time', 0); | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
use Hug\Ftp\Ftp as Ftp; | ||
|
||
|
||
$FtpServer = 'ip or hostname'; | ||
$FtpUser = 'username'; | ||
$FtpPass = 'password'; | ||
$FtpPath = 'public_html'; | ||
|
||
|
||
|
||
# | ||
$test = Ftp::scandir($FtpServer, $FtpUser, $FtpPass, $FtpPath); | ||
echo "scandir\n"; | ||
var_dump($test); | ||
|
||
# | ||
$test = Ftp::test($FtpServer, $FtpUser, $FtpPass); | ||
echo "Test\n"; | ||
var_dump($test); | ||
|
||
# Check Login Directory PWD | ||
$test = Ftp::pwd($FtpServer, $FtpUser, $FtpPass); | ||
echo "pwd\n"; | ||
var_dump($test); | ||
|
||
|
||
|
||
# Upload File | ||
$local_file = __DIR__ . '/test.txt'; | ||
$remote_file = $FtpPath . '/test.txt'; | ||
$test = Ftp::upload($FtpServer, $FtpUser, $FtpPass, $local_file, $remote_file); | ||
echo "upload\n"; | ||
var_dump($test); | ||
|
||
# Download File | ||
$local_file = __DIR__ . '/test-download.txt'; | ||
$remote_file = $FtpPath . '/test.txt'; | ||
$test = Ftp::download($FtpServer, $FtpUser, $FtpPass, $remote_file, $local_file); | ||
echo "download\n"; | ||
var_dump($test); | ||
unlink($local_file); | ||
|
||
# Rename File | ||
$old_file = $FtpPath . '/test.txt'; | ||
$new_file = $FtpPath . '/test-renamed.txt'; | ||
$test = Ftp::rename($FtpServer, $FtpUser, $FtpPass, $old_file, $new_file); | ||
echo "rename\n"; | ||
var_dump($test); | ||
|
||
# Test file exist | ||
$remote_file = $FtpPath . '/test-renamed.txt'; | ||
$test = Ftp::is_file($FtpServer, $FtpUser, $FtpPass, $remote_file); | ||
echo "is_file\n"; | ||
var_dump($test); | ||
|
||
# Delete File | ||
$remote_file = $FtpPath . '/test-renamed.txt'; | ||
$test = Ftp::delete($FtpServer, $FtpUser, $FtpPass, $remote_file); | ||
echo "delete\n"; | ||
var_dump($test); | ||
|
||
|
||
|
||
# Upload Folder | ||
// if ends with a slash upload content | ||
// if no slash end upload dir itself | ||
$local_path = __DIR__ . '/../src/'; | ||
$remote_path = $FtpPath . '/'; | ||
$test = Ftp::upload_dir($FtpServer, $FtpUser, $FtpPass, $local_path, $remote_path); | ||
echo "upload_dir\n"; | ||
var_dump($test); | ||
|
||
# Download Folder | ||
// if ends with a slash download content | ||
// if no slash end download dir itself | ||
$remote_dir = '/' . $FtpPath . '/src/'; | ||
$local_dir = __DIR__; | ||
$test = Ftp::download_dir($FtpServer, $FtpUser, $FtpPass, $remote_dir, $local_dir); | ||
echo "download_dir\n"; | ||
var_dump($test); | ||
|
||
# Delete Folder | ||
// if ends with a slash delete content | ||
// if no slash delete dir itself | ||
$remote_path = '/'.$FtpPath . '/Hug'; | ||
$test = Ftp::rmdir($FtpServer, $FtpUser, $FtpPass, $remote_path); | ||
echo "rmdir\n"; | ||
var_dump($test); | ||
|
||
|
||
|
||
# Create File | ||
$file_name = $FtpPath . '/test.txt'; | ||
$file_content = 'Love it !'; | ||
$test = Ftp::touch($FtpServer, $FtpUser, $FtpPass, $file_name, $file_content); | ||
echo "touch\n"; | ||
var_dump($test); | ||
|
||
# Delete File | ||
$remote_file = $FtpPath . '/test.txt'; | ||
$test = Ftp::delete($FtpServer, $FtpUser, $FtpPass, $remote_file); | ||
echo "delete\n"; | ||
var_dump($test); | ||
|
||
|
||
|
||
# Create Folder | ||
$directory = '/' . $FtpPath . '/coucou'; | ||
$test = Ftp::mkdir($FtpServer, $FtpUser, $FtpPass, $directory); | ||
echo "mkdir\n"; | ||
var_dump($test); | ||
|
||
# Rename Folder | ||
$old_file = $FtpPath . '/coucou'; | ||
$new_file = $FtpPath . '/coco'; | ||
$test = Ftp::rename($FtpServer, $FtpUser, $FtpPass, $old_file, $new_file); | ||
echo "rename"; | ||
var_dump($test); | ||
|
||
# Delete Folder | ||
$remote_path = $FtpPath . '/coco'; | ||
$test = Ftp::rmdir($FtpServer, $FtpUser, $FtpPass, $remote_path); | ||
echo "rmdir\n"; | ||
var_dump($test); | ||
|
||
|
||
$test = Ftp::scandir($FtpServer, $FtpUser, $FtpPass, $FtpPath); | ||
echo "scandir"; | ||
var_dump($test); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
coucou |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# php-ftp | ||
|
||
PHP FTP Utilities | ||
|
||
If you also need SFTP : [php-sftp](https://github.com/hugsbrugs/php-sftp) | ||
|
||
## Install | ||
|
||
Install package with composer | ||
``` | ||
composer require hugsbrugs/php-ftp | ||
``` | ||
|
||
In your PHP code, load librairy | ||
```php | ||
require_once __DIR__ . '/vendor/autoload.php'; | ||
use Hug\Ftp\Ftp as Ftp; | ||
``` | ||
|
||
## Usage | ||
|
||
Test FTP connection | ||
```php | ||
Ftp::test($server, $user, $password, $port = 21); | ||
``` | ||
|
||
Check if a file exists on Ftp Server | ||
```php | ||
Ftp::is_file($server, $user, $password, $remote_file, $port = 21); | ||
``` | ||
|
||
Delete a file on remote FTP server | ||
```php | ||
Ftp::delete($server, $user, $password, $remote_file, $port = 21); | ||
``` | ||
|
||
Recursively deletes files and folder in given directory (If remote_path ends with a slash delete folder content otherwise delete folder itself) | ||
```php | ||
Ftp::rmdir($server, $user, $password, $remote_path, $port = 21); | ||
``` | ||
|
||
Recursively copy files and folders on remote FTP server (If local_path ends with a slash upload folder content otherwise upload folder itself) | ||
```php | ||
Ftp::upload_dir($server, $user, $password, $local_path, $remote_path, $port = 21); | ||
``` | ||
|
||
Download a file from remote Ftp server | ||
```php | ||
Ftp::download($server, $user, $password, $remote_file, $local_file, $port = 21); | ||
``` | ||
|
||
Download a directory from remote FTP server (If remote_dir ends with a slash download folder content otherwise download folder itself) | ||
```php | ||
Ftp::download_dir($server, $user, $password, $remote_dir, $local_dir, | ||
$port = 21); | ||
``` | ||
|
||
Rename a file on remote FTP server | ||
```php | ||
Ftp::rename($server, $user, $password, $old_file, $new_file, $port = 21); | ||
``` | ||
|
||
Create a directory on remote FTP server | ||
```php | ||
Ftp::mkdir($server, $user, $password, $directory, $port = 21); | ||
``` | ||
|
||
Create a file on remote FTP server | ||
```php | ||
Ftp::touch($server, $user, $password, $remote_file, $content, $port = 21); | ||
``` | ||
|
||
Upload a file on FTP server | ||
```php | ||
Ftp::upload($server, $user, $password, $local_file, $remote_file = '', $port = 21); | ||
``` | ||
|
||
List files on FTP server | ||
```php | ||
Ftp::scandir($server, $user, $password, $path, $port = 21); | ||
``` | ||
|
||
Get default login FTP directory aka pwd | ||
```php | ||
Ftp::pwd($server, $user, $password, $port = 21); | ||
``` | ||
|
||
## Tests | ||
|
||
Edit example/test.php with your FTP parameters then run | ||
```php | ||
php example/test.php | ||
``` | ||
|
||
## To Do | ||
|
||
PHPUnit Tests | ||
|
||
## Author | ||
|
||
Hugo Maugey [visit my website ;)](https://hugo.maugey.fr) |
Oops, something went wrong.