rikless/laravel-ftp

A simple Laravel ftp service provider

This package's canonical repository appears to be gone and the package has been frozen as a result.

v0.0.2 2015-02-23 11:59 UTC

This package is auto-updated.

Last update: 2019-04-12 22:49:21 UTC


README

A simple Laravel 5 ftp service provider, forked from anchu/ftp package.

Installation

Add the package to your composer.json and run composer update.

{
    "require": {
        "rikless/laravel-ftp": "dev-master"
    }
}

Add the service provider in config/app.php:

'Anchu\Ftp\FtpServiceProvider',

Configuration

Run php artisan vendor:publish and modify the config file(/config/ftp.php) with your ftp connections.

You can add dynamic FTP connections with following syntax

Config::set('ftp::connections.key', array(
           'host'   => '',
           'username' => '',
           'password'   => '',
           'passive'   => false,
));

Accessing connections

You can access default FTP connection via the FTP::connection method:

FTP::connection()->getDirListing(...);

When using multiple connections you can access each specific ftp connection by passing connection name:

FTP::connection('foo')->getDirListing(...);

Sometimes you may need to reconnect to a given ftp:

FTP::reconnect('foo');

If you need to disconnect from a given ftp use the disconnect method:

FTP::disconnect('foo');

Basic usage examples

// With custom connection
$listing = FTP::connection('my-ftp-connection')->getDirListing();

// with default connection
$listing = FTP::connection()->getDirListing();
$status = FTP::connection()->makeDir('directory-name');

Supported methods

getDirListing($directory, $parameters )

Returns a list of files in the given directory

  • $directory: The directory to be listed. Default value: ..
  • $parameters: Optional parameters to prefix with directory. For example: -la. Default: null.

makeDir($directory)

Creates the specified directory on the FTP server.

  • $directory: The name of the directory that will be created.

changeDir($directory)

Changes the current directory on a FTP server.

  • $directory: The target directory.

uploadFile($fileFrom, $fileTo)

Uploads a local file to the FTP server.

  • $fileFrom: The local file path.
  • $fileTo: The remote file path.

downloadFile($fileFrom, $fileTo)

Downloads a file from the FTP server

  • $fileFrom: The remote file path.
  • $fileTo: The local file path (will be overwritten if the file already exists).

readFile($fileFrom)

Same as the downloadFile() method except it downloads the remote file to the PHP output buffer and returns it.

  • $fileFrom: The remote file path.

moveUp()

Changes to the parent directory.

permission($mode, $filename)

Set permissions on a file.

  • $mode: The new permissions, given as an octal value.
  • $filename: The remote file.

delete($path)

Deletes the file specified by path from the FTP server.

  • $path: The file to delete.

currentDir()

Returns the current directory name

rename($oldName, $newName)

Renames a file or a directory on the FTP server.

  • $oldName: The old file/directory name.
  • $newName: The new name.

removeDir($directory)

Removes a directory

  • $directory: The directory to delete. This must be either an absolute or relative path to an empty directory.

size($remoteFile)

Returns the size of the given file in bytes. Note: Not all servers support this feature.

  • $remoteFile: The remote file.

time($remoteFile)

Returns the last modified time of the given file Note: Not all servers support this feature.

  • $remoteFile: The remote file.