[how-to] Get FTP settings for site application
Original Publishing Date:
2020-01-22
Problem
In APS1 it was possible to get FTP settings using this environmental variables:
-
FTP_<identifier>_HOST
– FQDN or IP address of FTP server.
-
FTP_<identifier>_PORT
– port number of FTP server.
-
FTP_<identifier>_PATH
– URL path to FTP folder.
-
FTP_<identifier>_LOGIN
– login of user with full access to FTP folder.
-
FTP_<identifier>_PASSWORD
– password of user with full access to FTP folder.
How it can be done in APS2?
Resolution
Here is instructions how to get all values from APS controller:
-
Host:
extract urls property from website websites the application is installed to:
GET "/aps/2/resources/" + website_id
-
Port
for now it is not possible to get port, it should be assumed that ftp port is default
-
Path
extract path property from website websites the application is installed to:
GET "/aps/2/resources/" + website_id
-
Login
get list of all users created for this website (see getUsers at Website Types documentation page):
GET "/aps/2/resources/" + website_id + "/users/ftp"
example from php-runtime:
$users = \APS\Request::getController()->getIo()->sendRequest("GET", "/aps/2/resources/".$this->test_website->resource->aps->id."/users/ftp");
-
Password
it is not possible to get passwords of existing users for security reasons, it's needed to create separate user for application and save his password (see addUser at [Website Types](http://dev.apsstandard.org/doc/spec/types/web/website.html "Website Types") documentation page)
examples from php-runtime:
-
create:
\APS\Request::getController()->getIo()->sendRequest("POST", "/aps/2/resources/".$this->test_website->resource->aps->id."/users/ftp", '{ "name": "user", "password": "pass"}');
-
modify:
\APS\Request::getController()->getIo()->sendRequest("PUT", "/aps/2/resources/".$this->test_website->resource->aps->id."/users/ftp/someuser", '{"password": "pass"}');
-
If you use php-runtime, the easiest way is to introduce separate property to hold an array of all web settings, you can then access any of them by using this pattern: $this->LINK_NAME->PROPERTY_NAME
For example, if you have link to environment/web:
# Webspace information
/**
* @link("http://aps-standard.org/types/infrastructure/environment/web/1.0")1;
*
*/
public $webenv;
to access host and path:
$this->webenv->urls[0]
$this->webenv->path
Internal content