voipforall / tftp-client
The missing PHP TFTP Client package compliant with RFC 1350
Requires
- php: ^8.1
- ext-sockets: *
- illuminate/support: ^10.0
Requires (Dev)
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.20
- pestphp/pest-plugin-laravel: ^2.0
README
TFTP Client for Laravel
A PHP TFTP Client compliant with the RFC 1350 compatible with Laravel Framework
Installation
You can install the package via composer:
composer require voipforall/tftp-client
Requirements
- PHP ^8.1 (with ext-sockets enabled)
- Laravel 10.x
Quick start
Configure in your .env
file the following entries
TFTP_HOST=127.0.0.1 TFTP_PORT=69
To upload files
use VoIPforAll\TFTPClient\TFTPClient; $client = new TFTPClient; $response = $client->put('path/to/your/file-to-send.txt'); dd($response) -> true
the put
method will return a boolean accordingly with the success of the operation.
To download files
use VoIPforAll\TFTPClient\TFTPClient; $client = new TFTPClient; $content = $client->get('file-to-download.txt'); dd($content) -> "Download Ok"
The get
method will return false
if something goes wrong, if the file exists and is readable will be returned its content.
Publish the config file
To publish the config file use the Artisan command vendor:publish
to copy the config file to your project
php artisan vendor:publish --tag=config
or
php artisan vendor:publish --provider=VoIPforAll\\TFTPClient\\TFTPClientServiceProvider
Multiples TFTP Connections
You can have multiple connections with different TFTP Servers, take a look in the tftp-client.php
config file
/* |-------------------------------------------------------------------------- | Default TFTP Connection Name |-------------------------------------------------------------------------- | | Here you may specify which of the TFTP connections below you wish | to use as your default connection for all TFTP operations. Of | course you may add as many connections you'd like below. | */ 'connection' => env('TFTP_CLIENT_CONNECTION', 'default'), /* |-------------------------------------------------------------------------- | TFTP Connections |-------------------------------------------------------------------------- | | Below you may configure each TFTP connection your application requires | access to. Be sure to include a valid base HOST and TRANSFER MODE, | otherwise you may not be able to connect in the server. | */ 'connections' => [ 'default' => [ 'host' => env('TFTP_HOST', '127.0.0.1'), 'port' => env('TFTP_PORT', 69), 'transfer_mode' => env('TFTP_TRANSFER_MODE', TransferModeEnum::OCTET->value), ], 'custom' => [ 'host' => env('TFTP_CUSTOM_HOST', 'tftp.myhost.com'), 'port' => env('TFTP_CUSTOM_PORT', 69), 'transfer_mode' => env('TFTP_CUSTOM_TRANSFER_MODE', TransferModeEnum::OCTET->value), ], ],
The available transfer modes are:
- netascii
- octet (default)
Check the RFC 1350 to more details about the transfer mode
Logging the operations
If you want to log all TFTP operations just set the TFTP_LOGGING
to true
in your .env
file. You can also select the appropriate log channel using the TFTP_LOGGER_CHANNEL
, the defalt log channel will be used if you leave this unset.
/* |-------------------------------------------------------------------------- | TFTP Logging |-------------------------------------------------------------------------- | | When TFTP_LOGGING is enabled, all connections and transfers | operations are logged using the application logging | driver selected in TFTP_LOGGER_CHANNEL. This | can assist in debugging issues and more. | */ 'logging' => env('TFTP_LOGGING', false), 'logger_channel' => env('TFTP_LOGGER_CHANNEL', env('LOG_CHANNEL')),
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email cristiano@voipforall.com.br instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.