Drive

Data storage

Opens connection to data storage.

Arguments

$name
Name of the drive in account preferences.
Default: First preference that is found.
$preferences
Connection parameters
If given, $name is the name of the Drive type.

Example

Read content from remote file:

$fileContent = $this->get('drive','my_drive')
    ->getFile('folder/remote_file.txt')
    ->read();

Connection

Set connection

Set account preferences for drive:

Set connection preferences to Sftp server:

drive:
  - Name:      my_sftp_drive
    Type:      sftp
    Host:      sftp.myhost.fi
    Username:  demouser
    Password:  1234

Connect to drive using account preferences:

$Drive = $this->get('drive','my_sftp_drive');

Use custom parameters

Connection parameters can be set when instantiating the Drive object.

$Drive = $this->get('drive','sftp',Array(
  'Host'     => 'sftp.myhost.com',
  'Username' => 'demouser',
  'Password' => '1234'
));

Reading remote files

List files in folder

List file names and types in given folder

foreach ( $Drive->getFolder('folder_name')->getFiles() as $File ){
    $txt .= "<p>{$File->getName()} {$File->getType()}</p>";
}

Read/write files

Get file pointer:

// Open directory, open file
$File = $Drive->getFolder('remote_folder')->getFile('remote.txt');

// Or call file directly from Drive object
$File = $Drive->getFile('remote_folder/remote.txt');

Write text to file:

// Use File pointer
$File->write($txt);

// Or write directly from Drive object
$Drive->writeFile('remote_folder/remote.txt',$txt);

Read text from file:

// Use File pointer
$txt = $File->read();

// Or read directly from Drive object
$txt = $Drive->readFile('remote_folder/remote.txt');

Send local file to drive:

// Use File pointer
$File->send('local.txt');

// Or send directly from Drive object
$Drive->sendFile('local.txt','remote_folder/remote.txt');

Load file from drive to local file:

// Use File pointer
$File->load('local.txt');

// Or load directly from Drive object
$Drive->loadFile('remote_folder/remote.txt','local.txt');

Driver types

Ftp

Using ftp.

Parameters  Type  Description
Host  url  Server
Username  string  Authentication user
Password  string  Authentication password
Port  int  Default: 21
Path string Initial folder

Ftps

Using Ftps (SSL)

Parameters  Type  Description
Host  url  Server
Username  string  Authentication user
Password  string  Authentication password
Port  int  Default: 22
Path string Initial folder

Sftp

Using sFtp (ssh2).

Parameters  Type  Description
Host  url  Server
UserName  string  Authentication user
PassWord  string  Authentication password
Port  int  Default: 22
Path string Initial folder

Full method list

eDriveStorage

File methods

Method  Return value  Description
getFile(path)  eDriveFile Get file object.
getFiles(path)  eDriveFile[] Alias to getFolder(path)->getFiles().
readFile(path) string Alias to getFile(path)->read().
writeFile(path,txt) bool Alias to getFile(path)->write().
sendFile(local,remote) bool Alias to getFile(remote)->send(local).
loadFile(remote,local) bool Alias to getFile(remote)->load(local).
deleteFile(path) bool Alias to getFile(path)->delete().

Directory methods

Method  Return value  Description
getFolder(path) eDriveFolder Get folder object.
setPath(path)  this  Set working path.
changePath(path)  this  Add path to working path.
getPath() string Working path.
changeFolder(path)  this  Add path to working path. alias to changePath()

Connection, parameters and errors

Method  Return value  Description
connect()  this  Open connection to remote host. Is done automaticly if not set.
close()  this  Close connection to remote host.
setParameters(array)  this  Set multiple parameters in array or object.
getParameters(array)  array  Get all parameters in array.
setParameter(name,value)  this  Set parameter value.
getParameter(name)  mixed  Get parameter value.
getErrors() array Get list of error messages.
isError() bool Return TRUE if there are any errors.

eDriveFile

File info

Method  Return value  Description
getName()  string File name.
getFilename()  string Path and filename.
getPath()  string Path to folder.
getType()  string File type in lowercase.
getSize()  int Filesize in readable form (t/kt/Mt).
getFilesize()  int Filesize in bytes.
getCreatedAt() string Y-m-d H:i:s of file created time.
getModifiedAt() string Y-m-d H:i:s of file modified time.
isType($type) bool Return TRUE, if file is given type.
isMatch($string) bool Return TRUE, if file name contains given string.

Read and write

Method  Return value  Description
read() string Get file content.
save($local_file) bool Save remote file to $local_file.
send($local_file) bool Save $local_file to remote file.
write($txt) bool Write $text to remote file.
rename($name) bool Rename remote file.
delete() bool Remove remote file.

eDriveFolder

Folder info

Method  Return value  Description
getFilename()  string Path and filename.
getPath()  string Path to folder.
getName()  string File name.

Files info

Method  Return value  Description
getFile(filename)  eDriveFile Get file object
getFiles() eDriveFile[] Get all files in folder.
countFiles() int Return the number if files in folder.
isFiles() bool Return TRUE is folder has files in it.
getFolders() eDriveFolder[] Get all folders in folder.
countFolders() int Return the number if folders in folder.
isFolders() bool Return TRUE is folder has folders in it.

Edit folder

Method  Return value  Description
delete() this Remove folder.
rename($name) this Rename folder.