This commit is contained in:
Laurent Destailleur
2025-07-01 15:29:15 +02:00
parent e5aae4d7e3
commit 2941cf1c19

View File

@@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2022-2023 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2022-2025 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2022 Anthony Berton <bertonanthony@gmail.com>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -122,9 +122,9 @@ function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $sect
/**
* Tell if an entry is a FTP directory
*
* @param resource $connect_id Connection handler
* @param string $dir Directory
* @return int 1=directory, 0=not a directory
* @param resource|FTP\Connection $connect_id Connection handler
* @param string $dir Directory
* @return int 1=directory, 0=not a directory
*/
function ftp_isdir($connect_id, $dir)
{
@@ -139,13 +139,11 @@ function ftp_isdir($connect_id, $dir)
/**
* Tell if an entry is a FTP directory
*
* @param resource $connect_id Connection handler
* @return boolean Result of closing
* @param resource|FTP\Connection $connect_id Connection handler
* @return boolean Result of closing
*/
function dol_ftp_close($connect_id)
{
global $conf;
// Close FTP connection
if ($connect_id) {
if (!getDolGlobalString('FTP_CONNECT_WITH_SFTP')) {
@@ -158,21 +156,18 @@ function dol_ftp_close($connect_id)
/**
* Delete a FTP file
*
* @param resource $connect_id Connection handler
* @param string $file File
* @param string $newsection $newsection
* @param resource|FTP\Connection $connect_id Connection handler
* @param string $file File
* @param string $newsection Directory
* @return bool
*/
function dol_ftp_delete($connect_id, $file, $newsection)
{
global $conf;
if (getDolGlobalString('FTP_CONNECT_WITH_SFTP')) {
$newsection = ssh2_sftp_realpath($connect_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169
}
// Remote file
$filename = $file;
$remotefile = $newsection.(preg_match('@[\\\/]$@', $newsection) ? '' : '/').$file;
$newremotefileiso = mb_convert_encoding($remotefile, 'ISO-8859-1');
@@ -188,22 +183,19 @@ function dol_ftp_delete($connect_id, $file, $newsection)
/**
* Download a FTP file
*
* @param resource $connect_id Connection handler
* @param string $localfile The local file path
* @param string $file The remote file path
* @param string $newsection $newsection
* @param resource|FTP\Connection $connect_id Connection handler
* @param string $localfile The local file path
* @param string $file The remote file path
* @param string $newsection Directory
* @return bool|resource
*/
function dol_ftp_get($connect_id, $localfile, $file, $newsection)
{
global $conf;
if (getDolGlobalString('FTP_CONNECT_WITH_SFTP')) {
$newsection = ssh2_sftp_realpath($connect_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169
}
// Remote file
$filename = $file;
$remotefile = $newsection.(preg_match('@[\\\/]$@', $newsection) ? '' : '/').$file;
$newremotefileiso = mb_convert_encoding($remotefile, 'ISO-8859-1');
@@ -217,22 +209,19 @@ function dol_ftp_get($connect_id, $localfile, $file, $newsection)
/**
* Upload a FTP file
*
* @param resource $connect_id Connection handler
* @param string $file File name
* @param string $localfile The path to the local file
* @param string $newsection $newsection
* @param resource|FTP\Connection $connect_id Connection handler
* @param string $file File name
* @param string $localfile The path to the local file
* @param string $newsection Directory
* @return bool
*/
function dol_ftp_put($connect_id, $file, $localfile, $newsection)
{
global $conf;
if (getDolGlobalString('FTP_CONNECT_WITH_SFTP')) {
$newsection = ssh2_sftp_realpath($connect_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169
}
// Remote file
$filename = $file;
$remotefile = $newsection.(preg_match('@[\\\/]$@', $newsection) ? '' : '/').$file;
$newremotefileiso = mb_convert_encoding($remotefile, 'ISO-8859-1');
@@ -246,21 +235,18 @@ function dol_ftp_put($connect_id, $file, $localfile, $newsection)
/**
* Remove FTP directory
*
* @param resource $connect_id Connection handler
* @param string $file File
* @param string $newsection $newsection
* @param resource|FTP\Connection $connect_id Connection handler
* @param string $file File
* @param string $newsection Directory
* @return bool
*/
function dol_ftp_rmdir($connect_id, $file, $newsection)
{
global $conf;
if (getDolGlobalString('FTP_CONNECT_WITH_SFTP')) {
$newsection = ssh2_sftp_realpath($connect_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169
}
// Remote file
$filename = $file;
$remotefile = $newsection.(preg_match('@[\\\/]$@', $newsection) ? '' : '/').$file;
$newremotefileiso = mb_convert_encoding($remotefile, 'ISO-8859-1');
@@ -275,15 +261,13 @@ function dol_ftp_rmdir($connect_id, $file, $newsection)
/**
* Remove FTP directory
*
* @param resource $connect_id Connection handler
* @param string $newdir Dir create
* @param string $newsection $newsection
* @param resource|FTP\Connection $connect_id Connection handler
* @param string $newdir Dir create
* @param string $newsection Directory
* @return bool|string
*/
function dol_ftp_mkdir($connect_id, $newdir, $newsection)
{
global $conf;
if (getDolGlobalString('FTP_CONNECT_WITH_SFTP')) {
$newsection = ssh2_sftp_realpath($connect_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169
}