38function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive = 0)
48 if (!is_numeric($ftp_port)) {
49 $mesg = $langs->transnoentitiesnoconv(
"FailedToConnectToFTPServer", $ftp_server, $ftp_port);
54 $connecttimeout = (!
getDolGlobalString(
'FTP_CONNECT_TIMEOUT') ? 40 : $conf->global->FTP_CONNECT_TIMEOUT);
56 dol_syslog(
'Try to connect with ssh2_connect');
57 $tmp_conn_id = ssh2_connect($ftp_server, $ftp_port);
59 dol_syslog(
'Try to connect with ftp_ssl_connect');
60 $connect_id = ftp_ssl_connect($ftp_server, $ftp_port, $connecttimeout);
63 $connect_id = ftp_connect($ftp_server, $ftp_port, $connecttimeout);
65 if (!empty($connect_id) || !empty($tmp_conn_id)) {
68 dol_syslog(
'Try to authenticate with ssh2_auth_password');
69 if (ssh2_auth_password($tmp_conn_id, $ftp_user, $ftp_password)) {
74 $newsectioniso = mb_convert_encoding($section,
'ISO-8859-1');
76 $connect_id = ssh2_sftp($tmp_conn_id);
78 dol_syslog(
'Failed to connect to SFTP after sssh authentication', LOG_DEBUG);
79 $mesg = $langs->transnoentitiesnoconv(
"FailedToConnectToSFTPAfterSSHAuthentication");
84 dol_syslog(
'Failed to connect to FTP with login '.$ftp_user, LOG_DEBUG);
85 $mesg = $langs->transnoentitiesnoconv(
"FailedToConnectToFTPServerWithCredentials");
90 if (ftp_login($connect_id, $ftp_user, $ftp_password)) {
93 ftp_pasv($connect_id,
true);
97 $newsectioniso = mb_convert_encoding($section,
'ISO-8859-1');
98 ftp_chdir($connect_id, $newsectioniso);
100 $mesg = $langs->transnoentitiesnoconv(
"FailedToConnectToFTPServerWithCredentials");
107 dol_syslog(
'FailedToConnectToFTPServer '.$ftp_server.
' '.$ftp_port, LOG_ERR);
108 $mesg = $langs->transnoentitiesnoconv(
"FailedToConnectToFTPServer", $ftp_server, $ftp_port);
113 $arrayresult = array(
'conn_id'=>$connect_id,
'ok'=>$ok,
'mesg'=>$mesg,
'curdir'=>$section,
'curdiriso'=>$newsectioniso);
170 $newsection = ssh2_sftp_realpath($connect_id,
".").
'/./';
175 $remotefile = $newsection.(preg_match(
'@[\\\/]$@', $newsection) ?
'' :
'/').$file;
176 $newremotefileiso = mb_convert_encoding($remotefile,
'ISO-8859-1');
179 dol_syslog(
"ftp/index.php ftp_delete ".$newremotefileiso);
181 return ssh2_sftp_unlink($connect_id, $newremotefileiso);
183 return @ftp_delete($connect_id, $newremotefileiso);
201 $newsection = ssh2_sftp_realpath($connect_id,
".").
'/./';
206 $remotefile = $newsection.(preg_match(
'@[\\\/]$@', $newsection) ?
'' :
'/').$file;
207 $newremotefileiso = mb_convert_encoding($remotefile,
'ISO-8859-1');
210 return fopen(
'ssh2.sftp://'.intval($connect_id).$newremotefileiso,
'r');
212 return ftp_get($connect_id, $localfile, $newremotefileiso, FTP_BINARY);
230 $newsection = ssh2_sftp_realpath($connect_id,
".").
'/./';
235 $remotefile = $newsection.(preg_match(
'@[\\\/]$@', $newsection) ?
'' :
'/').$file;
236 $newremotefileiso = mb_convert_encoding($remotefile,
'ISO-8859-1');
239 return ssh2_scp_send($connect_id, $localfile, $newremotefileiso, 0644);
241 return ftp_put($connect_id, $newremotefileiso, $localfile, FTP_BINARY);
258 $newsection = ssh2_sftp_realpath($connect_id,
".").
'/./';
263 $remotefile = $newsection.(preg_match(
'@[\\\/]$@', $newsection) ?
'' :
'/').$file;
264 $newremotefileiso = mb_convert_encoding($remotefile,
'ISO-8859-1');
267 return ssh2_sftp_rmdir($connect_id, $newremotefileiso);
269 return @ftp_rmdir($connect_id, $newremotefileiso);
287 $newsection = ssh2_sftp_realpath($connect_id,
".").
'/./';
291 $newremotefileiso = $newsection.(preg_match(
'@[\\\/]$@', $newsection) ?
'' :
'/').$newdir;
292 $newremotefileiso = mb_convert_encoding($newremotefileiso,
'ISO-8859-1');
295 return ssh2_sftp_mkdir($connect_id, $newremotefileiso, 0777);
297 return @ftp_mkdir($connect_id, $newremotefileiso);
dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive=0)
Connect to FTP server.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.