diff --git a/htdocs/core/lib/ftp.lib.php b/htdocs/core/lib/ftp.lib.php index 42f5806fba5..928a7e4a934 100644 --- a/htdocs/core/lib/ftp.lib.php +++ b/htdocs/core/lib/ftp.lib.php @@ -218,6 +218,35 @@ function dol_ftp_get($connect_id, $file, $newsection) } } +/** + * Upload a FTP file + * + * @param resource $connect_id Connection handler + * @param string $file File + * @param string $newsection $newsection + * @return result + */ +function dol_ftp_put($connect_id, $file, $newsection) +{ + + global $conf; + + if (!empty($conf->global->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 = utf8_decode($remotefile); + + if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) { + return fopen('ssh2.sftp://'.intval($connect_id).$newremotefileiso, 'r'); + } else { + return ftp_put($connect_id, $localfile, $newremotefileiso, FTP_BINARY); + } +} + /** * Remove FTP directory *