Constants

SORT_ASC

SORT_ASC

Defines the sort direction as ascending

SORT_DESC

SORT_DESC

Defines the sort direction as descending

P_RETRY_COUNT

P_RETRY_COUNT

Defines a parameter as "retry count"

P_RETRY_TIME

P_RETRY_TIME

Defines a parameter as "retry wait time"

Properties

$url

$url : string

The endpoint URL

Type

string

$user

$user : string

The SFTP username

Type

string

$pubkey

$pubkey : string

Path to the public authentication key

Type

string

$privkey

$privkey : string

Path to the private authentication key

Type

string

$pw

$pw : string

Private authentication key password

Type

string

$dir

$dir : string

Directory in use

Type

string

$connection

$connection : resource

The SSH2 connection

Type

resource

$sftp

$sftp : resource

The SFTP subsystem

Type

resource

$local_dir

$local_dir : string

The local directory set

Type

string

$retry_count_max

$retry_count_max : integer

Maximum amount of retries for an operation

Type

integer

$retry_time

$retry_time : integer

Time in seconds between retries

Type

integer

Methods

__construct()

__construct(array  $params = array()) 

Instantiates the library

Parameters

array $params

Optional parameters - see class P_* constants

Throws

\Alo\Exception\ExtensionException

When the SSH2 extension is not loaded

retryCount()

retryCount(integer  $int = -1) : boolean|integer

If no parameter is passed gets the maximum amount of retry attempts for failed operations, otherwise sets it.

Parameters

integer $int

The amount

Returns

boolean|integer

retryTime()

retryTime(integer  $int = -1) : boolean

If no parameter is passed gets the time to wait between operation retries, otherwise sets it

Parameters

integer $int

The time in seconds

Returns

boolean

loc()

loc(string  $dir) : \Alo\SFTP

Sets the local directory

Parameters

string $dir

The directory path

Returns

\Alo\SFTP

scandir()

scandir(integer  $sorting_order = self::SORT_ASC) : array

Scans a directory for files and subdirectories

Parameters

integer $sorting_order

The sorting order

Returns

array —

["dirs" => [], "files" => []]

checkSubsystem()

checkSubsystem() : \Alo\SFTP

Checks if the SFTP subsystem was initialised

Returns

\Alo\SFTP

connect()

connect(integer  $attempt) : \Alo\SFTP

Creates a SSH2 connection

Parameters

integer $attempt

Current attempt number

Throws

\Alo\Exception\SFTPException

When the connection ultimately fails

Returns

\Alo\SFTP

downloadFile()

downloadFile(string  $file) : \Alo\SFTP

Downloads a file to $this->local_dir

Parameters

string $file

Remote file name

Returns

\Alo\SFTP

getFileContents()

getFileContents(string  $file) : string

Gets the file contents

Parameters

string $file

File name

Throws

\Alo\Exception\SFTPException

When the file cannot be fetched

Returns

string —

String representation of the file

upload()

upload(string  $file) : boolean

Uploads a file to the SFTP folder from the local folder

Parameters

string $file

File name

Throws

\Alo\Exception\SFTPException

When the local file cannot be read

Returns

boolean

makeFile()

makeFile(string  $file, mixed  $content) : boolean

Creates a file in the SFTP directory

Parameters

string $file

File name

mixed $content

File content

Throws

\Alo\Exception\SFTPException

When remote fopen fails

Returns

boolean

delete()

delete(string  $item) : boolean

Deletes an item on the SFTP server

Parameters

string $item

File or directory name

Returns

boolean

__toString()

__toString() : string

Returns a string representation of SFTP credentials

Returns

string

url()

url(string  $url = '') : \Alo\SFTP

If no parameter is passed gets the SFTP server URL, otherwise sets it.

Parameters

string $url

Throws

\Alo\Exception\SFTPException

When the URL is not a string

Returns

\Alo\SFTP

user()

user(string  $user = '') : \Alo\SFTP

If no parameter is passed gets the SFTP username, otherwise sets it.

Parameters

string $user

The username

Throws

\Alo\Exception\SFTPException

When $user isn't scalar

Returns

\Alo\SFTP

pubkey()

pubkey(string  $pubkey = '') : \Alo\SFTP

Sets the SFTP public key path

Parameters

string $pubkey

The path

Throws

\Alo\Exception\SFTPException

When $pubkey isn't a string

Returns

\Alo\SFTP

privkey()

privkey(string  $privkey = '') : \Alo\SFTP

If no parameter is passed gets the SFTP private key path, otherwise sets it

Parameters

string $privkey

The path

Throws

\Alo\Exception\SFTPException

When the $privkey isn't a string

Returns

\Alo\SFTP

pw()

pw(string  $pw = '') : \Alo\SFTP

If no parameter is passed gets the SFTP private key password, otherwise sets it

Parameters

string $pw

The password

Throws

\Alo\Exception\SFTPException

When the password isn't scalar

Returns

\Alo\SFTP

dir()

dir(mixed  $dir = -1) : \Alo\SFTP

If no argument is passed, gets the working directory, otherwise sets it.

Parameters

mixed $dir

Throws

\Alo\Exception\SFTPException

When the name is invalid

Returns

\Alo\SFTP

auth()

auth(integer  $attempt) : \Alo\SFTP

Authenticates the SSH2 connection

Parameters

integer $attempt

The current attempt # at authentication

Throws

\Alo\Exception\SFTPException

When authentication permanently fails

Returns

\Alo\SFTP

ssh2_sftp()

ssh2_sftp(integer  $attempt) : \Alo\SFTP

Initialises the SFTP subsystem

Parameters

integer $attempt

Current retry number

Throws

\Alo\Exception\SFTPException

When initialising the SFTP system permanently fails

Returns

\Alo\SFTP

isFile()

isFile(string  $resource) : boolean

Checks whether a resource is a file or directory based on whether it has a file extension

Parameters

string $resource

The resource name to check

Returns

boolean

resolvePath()

resolvePath(string  $item) : string

Modifies the path based on whether it's relative or absolute

Parameters

string $item

Item name

Returns

string —

The resolved path