File transfer

Event Listener: Skynet\EventListener\SkynetEventListenerFiles

Skynet can gets and writes remote files via one command. You can open any file (if you have correct privilleges) on remote server where Skynet cluster is placed, read its data and get this data in response. You can also put remote file by sending request and defining data to save.

Get remote file



To read remote file from server where Skynet cluster is placed use command:

@fget

This command takes one parameter - path:

path:"PATH_TO_FILE";

By example, after Skynet cluster receives request:

@fget path:"file.txt";

(or via PHP code):

/src/SkynetUser/MyListener.php
public function onRequest($context)
{
if($context == "beforeSend")
{
$this->request->set('@fget', array('path' => 'file.txt'));
}
}

then cluster whitch receive this request will try to open file called file.txt and read its content.
If success then content of this file will be returned in response in parameter:

@<<fgetFile


This parameter will be have content of readed file.
Received remote content will be also saved in /_download directory where Skynet cluster is placed.

If any errors occurs (file not exists or no access) then information about it will be returned in paramterer:

@<<fgetStatus

To put a file on remote server where Skynet cluster is placed use command:


Write remote file



@fput

This command takes two parameters:

path:"PATH_TO_FILE", data:"DATA_TO_SAVE";

or

path:"PATH_TO_FILE", source:"PATH_TO_LOCAL_FILE";

By example, if you want put file file.txt with data some_text just use a command:

@fput path:"file.txt", data:"some_text";

or via PHP code:

/src/SkynetUser/MyListener.php
public function onRequest($context)
{
if($context == "beforeSend")
{
$this->request->set('@fput', array('path' => 'file.txt', 'data' => 'some_text'));
}
}

Against data defining you can send local file by using param "source" as on example below:

@fput path:"file.txt", source:"local.txt";

Will send local.txt to remote and save it as file.txt

Result of file saving/upload will be returned in response in field:

@<<fputStatus


Delete remote file



To delete remote file use command:

@fdel path:"PATH_TO_FILE";

Result of file delete will be returned in response in field:

@<<fdelStatus


Delete remote directory



To delete remote directory use command:

@rmdir path:"PATH_TO_DIR";

Result of directory delete will be returned in response in field:

@<<rmdirStatus


Create remote directory



To create remote directory use:

@mkdir path:"PATH_TO_DIR";

Result of directory creation will be returned in response in field:

@<<mkdirStatus


Get remote files/dirs listing



To receive remote files list use command:

@ls;

Without arguments this command will get remote files and dirs list in cluster's directory

To receive list from specified directory use param "path":

@ls path:"PATH_ON_REMOTE";

To receive only specified file types create pattern by parameter "pattern" (default pattern value is: *), e.g.:

@ls path:"some_dir", pattern:"*.txt";

This will return .txt files list from directory "some_dir".

Returned data from command @ls is receiving by field:

@<<lsStatus

whitch is status of listing, and in:

@<<lsOutput[]

whitch is an array with remote files/dirs list.


Zip packer/unpacker



With Skynet you can send ZIP archive into remote cluster and tell Skynet to unpack files from it.
To send archive use command:

@zip_put path:"/path/to/", file:"local.zip";

Command above will send local file "local.zip" into remote cluster and then archive will be unpacked into directory "/path/to".

Result of operation will be returned by:

@<<zip_putStatus

If you want to pack files on remote cluster and get packed files as zip archive use command:

@zip_get path:"/path/to/", pattern:"*", file:"local.zip";

With command above Skynet will pack remote files from remote directory "/path/to" into zip archive and gets this archive in response.
After this an archive will be stored into "/_download" folder with name "local.zip".

Result of this operation will be returned by:

@<<zip_getStatus

Full API Documentation is included in Skynet packages available on GitHub.