AloFramework documentation
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo

Namespaces

  • Alo
    • Cache
    • CLI
    • Controller
    • Db
    • Exception
    • FileSystem
    • Session
    • Statics
    • Validators
    • Windows
  • Controller
  • None
  • PHP

Classes

  • Cron
  • Curl
  • Email
  • Handler
  • Locale
  • Profiler
  • SFTP

Class SFTP

SFTP handler

Namespace:Alo
Author:Arturas Molcanovas <a.molcanovas@gmail.com>
Located atsys/class/alo/sftp.php

Methods summary

public
#__construct(array$params= [])

Instantiates the library

Instantiates the library

Parameters

$params
array
$params Optional parameters - see class P_* constants

Throws

Alo\Exception\ExtensionException
When the SSH2 extension is not loaded

See

Alo\SFTP::P_RETRY_COUNT
Alo\SFTP::P_RETRY_TIME
public staticAlo\SFTP
#sftp(array$params= [])

Instantiates the library

Instantiates the library

Parameters

$params
array
$params Optional parameters - see class P_* constants

Returns

Alo\SFTP

Throws

Alo\Exception\ExtensionException
When the SSH2 extension is not loaded

See

Alo\SFTP::P_RETRY_COUNT
Alo\SFTP::P_RETRY_TIME
public boolean|integer
#retryCount(integer$int= -1)

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

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

Parameters

$int
integer
$int The amount

Returns

boolean|integer

Author

Art <a.molcanovas@gmail.com>
public boolean
#retryTime(integer$int= -1)

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

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

Parameters

$int
integer
$int The time in seconds

Returns

boolean

Author

Art <a.molcanovas@gmail.com>
publicAlo\SFTP
#loc(string$dir)

Sets the local directory

Sets the local directory

Parameters

$dir
string
$dir The directory path

Returns

Alo\SFTP

Author

Art <a.molcanovas@gmail.com>
public array
#scandir(integer$sortingOrder=Alo\SFTP::SORT_ASC)

Scans a directory for files and subdirectories

Scans a directory for files and subdirectories

Parameters

$sortingOrder
integer
$sortingOrder The sorting order

Returns

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

Author

Art <a.molcanovas@gmail.com>
publicAlo\SFTP
#checkSubsystem( )

Checks if the SFTP subsystem was initialised

Checks if the SFTP subsystem was initialised

Returns

Alo\SFTP

Throws

Alo\Exception\SFTPException
When the connection ultimately fails

Author

Art <a.molcanovas@gmail.com>
publicAlo\SFTP
#connect(integer$attempt=0)

Creates a SSH2 connection

Creates a SSH2 connection

Parameters

$attempt
integer
$attempt Current attempt number

Returns

Alo\SFTP

Throws

Alo\Exception\SFTPException
When the connection ultimately fails

Author

Art <a.molcanovas@gmail.com>
protectedAlo\SFTP
#auth(integer$attempt=0)

Authenticates the SSH2 connection

Authenticates the SSH2 connection

Parameters

$attempt
integer
$attempt The current attempt # at authentication

Returns

Alo\SFTP

Throws

Alo\Exception\SFTPException
When authentication permanently fails

Author

Art <a.molcanovas@gmail.com>
protectedAlo\SFTP
#ssh2Sftp(integer$attempt=0)

Initialises the SFTP subsystem

Initialises the SFTP subsystem

Parameters

$attempt
integer
$attempt Current retry number

Returns

Alo\SFTP

Throws

Alo\Exception\SFTPException
When initialising the SFTP system permanently fails

Author

Art <a.molcanovas@gmail.com>
protected static boolean
#isFile(string$resource)

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

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

Parameters

$resource
string
$resource The resource name to check

Returns

boolean

Author

Art <a.molcanovas@gmail.com>
publicAlo\SFTP
#downloadFile(string$file)

Downloads a file to $this->localDir

Downloads a file to $this->localDir

Parameters

$file
string
$file Remote file name

Returns

Alo\SFTP

Throws

Alo\Exception\SFTPException
When the file cannot be fetched
Alo\Exception\FileSystemException
When the name is invalid

Author

Art <a.molcanovas@gmail.com>

See

Alo\SFTP::$localDir
public string
#getFileContents(string$file)

Gets the file contents

Gets the file contents

Parameters

$file
string
$file File name

Returns

string
String representation of the file

Throws

Alo\Exception\SFTPException
When the file cannot be fetched

Author

Art <a.molcanovas@gmail.com>
protected string
#resolvePath(string$item)

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

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

Parameters

$item
string
$item Item name

Returns

string
The resolved path

Author

Art <a.molcanovas@gmail.com>
public boolean
#upload(string$file)

Uploads a file to the SFTP folder from the local folder

Uploads a file to the SFTP folder from the local folder

Parameters

$file
string
$file File name

Returns

boolean

Throws

Alo\Exception\SFTPException
When the local file cannot be read

Author

Art <a.molcanovas@gmail.com>
public boolean
#makeFile(string$file,mixed$content)

Creates a file in the SFTP directory

Creates a file in the SFTP directory

Parameters

$file
string
$file File name
$content
mixed
$content File content

Returns

boolean

Throws

Alo\Exception\SFTPException
When remote fopen fails

Author

Art <a.molcanovas@gmail.com>
public boolean
#delete(string$item)

Deletes an item on the SFTP server

Deletes an item on the SFTP server

Parameters

$item
string
$item File or directory name

Returns

boolean

Author

Art <a.molcanovas@gmail.com>
public string
#__toString( )

Returns a string representation of SFTP credentials

Returns a string representation of SFTP credentials

Returns

string

Author

Art <a.molcanovas@gmail.com>
publicAlo\SFTP
#url(string$url='')

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

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

Parameters

$url
string
$url

Returns

Alo\SFTP

Throws

Alo\Exception\SFTPException
When the URL is not a string

Author

Art <a.molcanovas@gmail.com>
publicAlo\SFTP
#user(string$user='')

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

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

Parameters

$user
string
$user The username

Returns

Alo\SFTP

Throws

Alo\Exception\SFTPException
When $user isn't scalar

Author

Art <a.molcanovas@gmail.com>
publicAlo\SFTP
#pubkey(string$pubkey='')

Sets the SFTP public key path

Sets the SFTP public key path

Parameters

$pubkey
string
$pubkey The path

Returns

Alo\SFTP

Throws

Alo\Exception\SFTPException
When $pubkey isn't a string

Author

Art <a.molcanovas@gmail.com>
publicAlo\SFTP
#privkey(string$privkey='')

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

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

Parameters

$privkey
string
$privkey The path

Returns

Alo\SFTP

Throws

Alo\Exception\SFTPException
When the $privkey isn't a string

Author

Art <a.molcanovas@gmail.com>
publicAlo\SFTP
#pw(string$pw='')

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

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

Parameters

$pw
string
$pw The password

Returns

Alo\SFTP

Throws

Alo\Exception\SFTPException
When the password isn't scalar

Author

Art <a.molcanovas@gmail.com>
publicAlo\SFTP
#dir(mixed$dir= -1)

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

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

Parameters

$dir
mixed
$dir

Returns

Alo\SFTP

Throws

Alo\Exception\SFTPException
When the name is invalid

Author

Art <a.molcanovas@gmail.com>

Magic methods summary

Constants summary

integerSORT_ASCSCANDIR_SORT_ASCENDING
#

Defines the sort direction as ascending

Defines the sort direction as ascending

integerSORT_DESCSCANDIR_SORT_DESCENDING
#

Defines the sort direction as descending

Defines the sort direction as descending

integerP_RETRY_COUNT101
#

Defines a parameter as "retry count"

Defines a parameter as "retry count"

integerP_RETRY_TIME102
#

Defines a parameter as "retry wait time"

Defines a parameter as "retry wait time"

Properties summary

public staticAlo\SFTP$this
#

Static reference to the last instance of the class

Static reference to the last instance of the class

protected string$url
#

The endpoint URL

The endpoint URL

protected string$user
#

The SFTP username

The SFTP username

protected string$pubkey
#

Path to the public authentication key

Path to the public authentication key

protected string$privkey
#

Path to the private authentication key

Path to the private authentication key

protected string$pw
#

Private authentication key password

Private authentication key password

protected string$dir
#

Directory in use

Directory in use

protected resource$connection
#

The SSH2 connection

The SSH2 connection

protected resource$sftp
#

The SFTP subsystem

The SFTP subsystem

protected string$localDir
#

The local directory set

The local directory set

protected integer$retryCountMax
#

Maximum amount of retries for an operation

Maximum amount of retries for an operation

protected integer$retryTime
#

Time in seconds between retries

Time in seconds between retries

AloFramework documentation API documentation generated byApiGen 2.8.0