Drive
Data storage
Data storage
Read content from remote file:
$fileContent = $this->get('drive','my_drive')
->getFile('folder/remote_file.txt')
->read();
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');
Connection parameters can be set when instantiating the Drive object.
$Drive = $this->get('drive','sftp',Array(
'Host' => 'sftp.myhost.com',
'Username' => 'demouser',
'Password' => '1234'
));
List file names and types in given folder
foreach ( $Drive->getFolder('folder_name')->getFiles() as $File ){
$txt .= "<p>{$File->getName()} {$File->getType()}</p>";
}
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');
Using ftp.
Parameters | Type | Description |
---|---|---|
Host | url | Server |
Username | string | Authentication user |
Password | string | Authentication password |
Port | int | Default: 21 |
Path | string | Initial folder |
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 |
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 |
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(). |
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() |
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. |
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. |
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. |
Method | Return value | Description |
---|---|---|
getFilename() | string | Path and filename. |
getPath() | string | Path to folder. |
getName() | string | File name. |
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. |
Method | Return value | Description |
---|---|---|
delete() | this | Remove folder. |
rename($name) | this | Rename folder. |