40 function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive = 0)
50 if (!is_numeric($ftp_port)) {
51 $mesg = $langs->transnoentitiesnoconv(
"FailedToConnectToFTPServer", $ftp_server, $ftp_port);
56 $connecttimeout = (empty($conf->global->FTP_CONNECT_TIMEOUT) ? 40 : $conf->global->FTP_CONNECT_TIMEOUT);
57 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
58 dol_syslog(
'Try to connect with ssh2_connect');
59 $tmp_conn_id = ssh2_connect($ftp_server, $ftp_port);
60 } elseif (!empty($conf->global->FTP_CONNECT_WITH_SSL)) {
61 dol_syslog(
'Try to connect with ftp_ssl_connect');
62 $connect_id = ftp_ssl_connect($ftp_server, $ftp_port, $connecttimeout);
65 $connect_id = ftp_connect($ftp_server, $ftp_port, $connecttimeout);
67 if (!empty($connect_id) || !empty($tmp_conn_id)) {
69 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
70 dol_syslog(
'Try to authenticate with ssh2_auth_password');
71 if (ssh2_auth_password($tmp_conn_id, $ftp_user, $ftp_password)) {
76 $newsectioniso = utf8_decode($section);
78 $connect_id = ssh2_sftp($tmp_conn_id);
80 dol_syslog(
'Failed to connect to SFTP after sssh authentication', LOG_DEBUG);
81 $mesg = $langs->transnoentitiesnoconv(
"FailedToConnectToSFTPAfterSSHAuthentication");
86 dol_syslog(
'Failed to connect to FTP with login '.$ftp_user, LOG_DEBUG);
87 $mesg = $langs->transnoentitiesnoconv(
"FailedToConnectToFTPServerWithCredentials");
92 if (ftp_login($connect_id, $ftp_user, $ftp_password)) {
95 ftp_pasv($connect_id,
true);
99 $newsectioniso = utf8_decode($section);
100 ftp_chdir($connect_id, $newsectioniso);
102 $mesg = $langs->transnoentitiesnoconv(
"FailedToConnectToFTPServerWithCredentials");
109 dol_syslog(
'FailedToConnectToFTPServer '.$ftp_server.
' '.$ftp_port, LOG_ERR);
110 $mesg = $langs->transnoentitiesnoconv(
"FailedToConnectToFTPServer", $ftp_server, $ftp_port);
115 $arrayresult = array(
'conn_id'=>$connect_id,
'ok'=>$ok,
'mesg'=>$mesg,
'curdir'=>$section,
'curdiriso'=>$newsectioniso);
129 if (@ftp_chdir($connect_id, $dir)) {
130 ftp_cdup($connect_id);
149 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
150 } elseif (!empty($conf->global->FTP_CONNECT_WITH_SSL)) {
151 return ftp_close($connect_id);
153 return ftp_close($connect_id);
171 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
172 $newsection = ssh2_sftp_realpath($connect_id,
".").
'/./';
177 $remotefile = $newsection.(preg_match(
'@[\\\/]$@', $newsection) ?
'' :
'/').$file;
178 $newremotefileiso = utf8_decode($remotefile);
181 dol_syslog(
"ftp/index.php ftp_delete ".$newremotefileiso);
182 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
183 return ssh2_sftp_unlink($connect_id, $newremotefileiso);
185 return @ftp_delete($connect_id, $newremotefileiso);
203 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
204 $newsection = ssh2_sftp_realpath($connect_id,
".").
'/./';
209 $remotefile = $newsection.(preg_match(
'@[\\\/]$@', $newsection) ?
'' :
'/').$file;
210 $newremotefileiso = utf8_decode($remotefile);
212 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
213 return fopen(
'ssh2.sftp://'.intval($connect_id).$newremotefileiso,
'r');
215 return ftp_get($connect_id, $localfile, $newremotefileiso, FTP_BINARY);
232 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
233 $newsection = ssh2_sftp_realpath($connect_id,
".").
'/./';
238 $remotefile = $newsection.(preg_match(
'@[\\\/]$@', $newsection) ?
'' :
'/').$file;
239 $newremotefileiso = utf8_decode($remotefile);
241 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
242 return ssh2_scp_send($connect_id, $localfile, $newremotefileiso, 0644);
244 return ftp_put($connect_id, $newremotefileiso, $localfile, FTP_BINARY);
260 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
261 $newsection = ssh2_sftp_realpath($connect_id,
".").
'/./';
266 $remotefile = $newsection.(preg_match(
'@[\\\/]$@', $newsection) ?
'' :
'/').$file;
267 $newremotefileiso = utf8_decode($remotefile);
269 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
270 return ssh2_sftp_rmdir($connect_id, $newremotefileiso);
272 return @ftp_rmdir($connect_id, $newremotefileiso);
289 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
290 $newsection = ssh2_sftp_realpath($connect_id,
".").
'/./';
294 $newremotefileiso = $newsection.(preg_match(
'@[\\\/]$@', $newsection) ?
'' :
'/').$newdir;
295 $newremotefileiso = utf8_decode($newremotefileiso);
297 if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
298 return ssh2_sftp_mkdir($connect_id, $newremotefileiso, 0777);
300 return @ftp_mkdir($connect_id, $newremotefileiso);
dol_ftp_mkdir($connect_id, $newdir, $newsection)
Remove FTP directory.
ftp_isdir($connect_id, $dir)
Tell if an entry is a FTP directory.
dol_ftp_close($connect_id)
Tell if an entry is a FTP directory.
dol_ftp_delete($connect_id, $file, $newsection)
Delete a FTP file.
dol_ftp_rmdir($connect_id, $file, $newsection)
Remove FTP directory.
dol_ftp_put($connect_id, $file, $localfile, $newsection)
Upload a FTP file.
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive=0)
Connect to FTP server.
dol_ftp_get($connect_id, $localfile, $file, $newsection)
Download a FTP file.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.