39function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive = 0)
49 if (!is_numeric($ftp_port)) {
50 $mesg = $langs->transnoentitiesnoconv(
"FailedToConnectToFTPServer", $ftp_server, $ftp_port);
55 $connecttimeout = (!
getDolGlobalString(
'FTP_CONNECT_TIMEOUT') ? 40 : $conf->global->FTP_CONNECT_TIMEOUT);
57 dol_syslog(
'Try to connect with ssh2_connect');
58 $tmp_conn_id = ssh2_connect($ftp_server, (
int) $ftp_port);
60 dol_syslog(
'Try to connect with ftp_ssl_connect');
61 $connect_id = ftp_ssl_connect($ftp_server, (
int) $ftp_port, $connecttimeout);
64 $connect_id = ftp_connect($ftp_server, (
int) $ftp_port, $connecttimeout);
66 if (!empty($connect_id) || !empty($tmp_conn_id)) {
69 dol_syslog(
'Try to authenticate with ssh2_auth_password');
70 if (ssh2_auth_password($tmp_conn_id, $ftp_user, $ftp_password)) {
75 $newsectioniso = mb_convert_encoding($section,
'ISO-8859-1');
77 $connect_id = ssh2_sftp($tmp_conn_id);
79 dol_syslog(
'Failed to connect to SFTP after sssh authentication', LOG_DEBUG);
80 $mesg = $langs->transnoentitiesnoconv(
"FailedToConnectToSFTPAfterSSHAuthentication");
85 dol_syslog(
'Failed to connect to FTP with login '.$ftp_user, LOG_DEBUG);
86 $mesg = $langs->transnoentitiesnoconv(
"FailedToConnectToFTPServerWithCredentials");
91 if (ftp_login($connect_id, $ftp_user, $ftp_password)) {
94 ftp_pasv($connect_id,
true);
98 $newsectioniso = mb_convert_encoding($section,
'ISO-8859-1');
99 if (!ftp_chdir($connect_id, $newsectioniso)) {
101 $mesg = $langs->transnoentitiesnoconv(
"FailedToChdirOnFTPServer");
105 $mesg = $langs->transnoentitiesnoconv(
"FailedToConnectToFTPServerWithCredentials");
110 dol_syslog(
'FailedToConnectToFTPServer '.$ftp_server.
' '.$ftp_port, LOG_ERR);
111 $mesg = $langs->transnoentitiesnoconv(
"FailedToConnectToFTPServer", $ftp_server, $ftp_port);
116 $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.