voipforall/tftp-client

The missing PHP TFTP Client package compliant with RFC 1350

v1.0 2023-11-24 02:23 UTC

This package is auto-updated.

Last update: 2024-05-24 03:39:29 UTC


README

285342232-cd0f5703-190d-4ab3-bf7d-21bce29fbf67.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTY1MjIyNjksIm5iZiI6MTcxNjUyMTk2OSwicGF0aCI6Ii8zMDk5MDA5Ny8yODUzNDIyMzItY2QwZjU3MDMtMTkwZC00YWIzLWJmN2QtMjFiY2UyOWZiZjY3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA1MjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNTI0VDAzMzkyOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTY1ZTRhMzQ5N2JmMmVmNjEzYjA4NDVjOWU4ZjA5MGRkYzMxZjM4ZWEyNzZkNmM2YjMwN2I2ODJhOTRlY2I0NzImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.P0_0gHkyTcYX4-EMz5qSywM9r_Ybpy2tUfhiwY44IZI

TFTP Client for Laravel

Latest Version on Packagist Total Downloads GitHub Actions

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)
  • mail

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.