How to connect FTP and open .txt file?

0

I'm trying to connect to an FTP to open a .txt file I need to save it in a database I have the following code but it does not work for me:

$archivo = fopen ("ftp://perez:[email protected]/u02/data/mensaje/SMS/SMS_WELCOME_CDR_20181108.txt", "r");
if (!$archivo) 
{
    echo "<p>No puedo abrir el archivo para lectura</p>";
    exit;
}

$texto="";
while ($linea = fgets($archivo,1024)) 
{
   if ($linea) $texto .= $linea;
}

echo $texto;
fclose ($archivo);

I get the following error:

Warning: fopen(ftp://[email protected]/u02/data/mensaje/SMS/SMS_WELCOME_CDR_20181108.txt) [function.fopen]: failed to open stream: Resource temporarily unavailable in /usr/local/apache2/htdocs/web/perez/sistema/proceso.php on line 14
    
asked by Juan Perez 09.11.2018 в 18:21
source

1 answer

0

you can use php ftp connect:

<?php

// definir algunas variables
$local_file = 'local.zip';
$server_file = 'server.zip';

// establecer una conexión básica
$conn_id = ftp_connect($ftp_server);

// iniciar sesión con nombre de usuario y contraseña
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// intenta descargar $server_file y guardarlo en $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
    echo "Se ha guardado satisfactoriamente en $local_file\n";
} else {
    echo "Ha habido un problema\n";
}

// cerrar la conexión ftp
ftp_close($conn_id);

?>

if you want to do it through sftp:

<?php
$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');

$sftp = ssh2_sftp($connection);

$stream = fopen("ssh2.sftp://$sftp/path/to/file", 'r');
?>

source:
ftp
link
sftp
link

    
answered by 09.11.2018 в 19:05