From 41291c82fdca670cf8bb20859d34b76974658810 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Wed, 2 Apr 2025 13:53:41 +0200 Subject: [PATCH] fx --- ci4/app/Services/ImpresoraEtiquetaService.php | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/ci4/app/Services/ImpresoraEtiquetaService.php b/ci4/app/Services/ImpresoraEtiquetaService.php index 5a797f3a..19e4e851 100644 --- a/ci4/app/Services/ImpresoraEtiquetaService.php +++ b/ci4/app/Services/ImpresoraEtiquetaService.php @@ -9,8 +9,6 @@ use DOMDocument; use DOMElement; use DOMText; use DOMNode; -use Error; -use Exception; use phpseclib3\Net\SFTP; use Throwable; @@ -83,25 +81,13 @@ class ImpresoraEtiquetaService extends BaseService } protected function sendToImpresoraEtiqueta(string $name, string $content, ImpresoraEtiquetaEntity $impresoraEtiqueta): bool { - $conn = @ftp_connect($impresoraEtiqueta->ip,$impresoraEtiqueta->port); - if(!$conn){ - throw new Exception('Error al establecer conexión FTP'); - } - $isLoginSuccess = @ftp_login($conn, $impresoraEtiqueta->user, $impresoraEtiqueta->pass); + $ftp = new SFTP($impresoraEtiqueta->ip, $impresoraEtiqueta->port); + $isLoginSuccess = $ftp->login(username: $impresoraEtiqueta->user, password: $impresoraEtiqueta->pass ?? ''); if ($isLoginSuccess) { + $status = $ftp->put($name, $content); } else { - throw new Exception('Error haciendo login en el servidor FTP'); - } - if (!ftp_pasv($conn, true)) { - throw new Exception('Error entrando en modo pasivo'); - } - if (ftp_put($conn, $name, $content, FTP_ASCII) === FALSE) { $status = false; - ftp_close($conn); - }else{ - $status = true; } - return $status; } }