mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
49 lines
1.4 KiB
PHP
49 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Libraries;
|
|
|
|
use FtpClient\FtpClient;
|
|
|
|
class SafekatFtpClient
|
|
{
|
|
protected FtpClient $ftp;
|
|
protected string $host;
|
|
protected int $port;
|
|
protected string $username;
|
|
protected string $password;
|
|
protected string $base_dir;
|
|
protected object $ftp_config;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->ftp = new FtpClient();
|
|
$this->ftp_config = config("FTP");
|
|
$this->host = $this->ftp_config->host;
|
|
$this->username = $this->ftp_config->username;
|
|
$this->password = $this->ftp_config->password;
|
|
$this->port = $this->ftp_config->port;
|
|
$this->base_dir = $this->ftp_config->base_dir;
|
|
}
|
|
/**
|
|
* Upload the content of $filename to the base directory declared in App\Config\FTP.php
|
|
*
|
|
* @param string $content
|
|
* @param string $filename
|
|
* @return boolean
|
|
*/
|
|
public function uploadXML(string $content, string $filename): bool
|
|
{
|
|
try {
|
|
$remotePath = implode("/", [$this->base_dir, $filename]);
|
|
$this->ftp->connect(host: $this->host, port: $this->port);
|
|
$this->ftp->login(username: $this->username, password: $this->password);
|
|
$this->ftp->putFromString($remotePath, $content);
|
|
return true;
|
|
} catch (\Throwable $th) {
|
|
throw $th;
|
|
log_message('error',$th->getMessage());
|
|
return false;
|
|
}
|
|
}
|
|
}
|