use Cubist\Util\CommandLine\Rclone;
use Cubist\Util\Files\Files;
+use Illuminate\Support\Facades\Log;
-class SFTP extends Driver {
+class SFTP extends Driver
+{
const ERROR_MISSING_HOST = 0;
const ERROR_SEND_FILE = 5;
- protected $port = 22;
+ const DEFAULT_PORT = 22;
- protected function synchronizeFiles($source, $dest, $mirror = false, $dryrun = false) {
+ protected function synchronizeFiles($source, $dest, $mirror = false, $dryrun = false)
+ {
$rclone = new Rclone();
$rclone->setServer($this->getServer());
$rclone->setSrc($source);
$rclone->execute();
return $rclone;
}
-
- public function checkConnexion($data = []) {
+
+ public function checkConnexion($data = [])
+ {
$connection = null;
- $data['port'] = $data['port'] ?? $this->port;
$data = [
'username' => $data['username'] ?? $this->getServer()->getUsername(),
'password' => $data['password'] ?? $this->getServer()->getPassword(),
'host' => $data['host'] ?? $this->getServer()->getHost(),
- 'port' => $data['port'] ?? $this->getServer()->getPort(),
+ 'port' => $data['port'] ?? $this->getServer()->getPort() ?? self::DEFAULT_PORT,
];
- if(!$data['host']) {
+ if (!$data['host']) {
return self::ERROR_MISSING_HOST;
} else {
try {
}
try {
- $tmp = Files::tempnam("/application"); //on créé un fichier temporaire en local
+ $tmp = Files::tempnam(); //on créé un fichier temporaire en local
$this->copyFile($tmp, '/');
- } catch(\Exception $e) {
+ } catch (\Exception $e) {
return static::ERROR_SEND_FILE;
}
try {
$filename = $this->getTestFilename($tmp);
$sftp = ssh2_sftp($connection);
- $basepath = '/'.trim($this->getServer()->getBasePath(), '/').'/';
- $f = @ssh2_sftp_stat($sftp, $basepath.$filename);
- ssh2_sftp_unlink($sftp, $basepath.$filename); //on supprime le fichier distant
+ $basepath = '/' . trim($this->getServer()->getBasePath(), '/') . '/';
+ $f = @ssh2_sftp_stat($sftp, $basepath . $filename);
+ ssh2_sftp_unlink($sftp, $basepath . $filename); //on supprime le fichier distant
ssh2_disconnect($connection); //on quitte la connexion
unlink($tmp); //on supprime le fichier temporaire en local
return true;
- } catch(\Exception $e) {
+ } catch (\Exception $e) {
return static::ERROR_SEND_FILE;
}
}
}
- public function getTestFilename($file) {
- $filepath = explode('/',$file);
+ public function getTestFilename($file)
+ {
+ $filepath = explode('/', $file);
return end($filepath);
}
}
\ No newline at end of file