In testing, I have been unable to establish any socket connections (including FTP connections) on shutdown. This is important if you are trying to save the FTP transfer to run after the php script has been executed (using register_shutdown_function). I am unaware of any configuration options that control this, and I have found this affects any socket connections I have tried to establish after shutdown.
The same code works fine if it is executed at runtime, rather than on shutdown. Since I found no documentation of this behavior, I felt it important to note somewhere. May also be useful if this was crosslinked to fsockopen comments as well.
ftp_connect
(PHP 4, PHP 5)
ftp_connect — Abre una conexión FTP
Descripción
ftp_connect() abre una conexión con el host especificado.
Lista de parámetros
- host
-
La dirección del servidor FTP. Este parámetro no debe tener barras al final, y no debe ser precedido por ftp://.
- puerto
-
Este parámetro especifica un puerto alterno para conectarse. Si es omitido, o es definido como cero, entonces el puerto predeterminado de FTP, 21, será usado.
- tiempo_espera
-
Este parámetro especifica el tiempo de espera para todas las operaciones de red subsiguientes. Si es omitido, el valor predeterminado es 90 segundos. El tiempo de espera puede ser modificado y consultado en cualquier momento con ftp_set_option() y ftp_get_option().
Valores retornados
Devuelve una secuencia FTP en caso de éxito, o FALSE si ocurre un error.
Ejemplos
Example #1 Ejemplo de ftp_connect()
<?php
$servidor_ftp = "ftp.example.com";
// configurar una conexion o abortar
$id_con = ftp_connect($servidor_ftp) or die("No ha sido posible conectarse a $servidor_ftp");
?>
Registro de cambios
| Versión | Descripción |
|---|---|
| 4.2.0 | Se agregó tiempo_espera . |
ftp_connect
10-Oct-2005 04:06
11-Nov-2003 08:07
Connecting through a firewall also depends on the type. This is an example for the Secure Gateway FTP. First you have to connect to the firewall, then open a session to the destination ftp server. This looks like this:
// Connect to firewall
$conn_id = ftp_connect("firewall.yournet.com");
// Open a session to an external ftp site
$login_result = ftp_login ($conn_id, "userid@externalhost.com", "password");
// Check open
if ((!$conn_id) || (!$login_result)) {
echo "Ftp-connect failed!"; die;
} else {
echo "Connected.";
}
// turn on passive mode transfers
ftp_pasv ($conn_id, true) ;
... and go on ...
03-Mar-2003 08:35
always keep an eye on the ftp_pasv function, if you are behind a firewall or nat'ed and your scripts won't do a listing or put files to the ftp
