Вопрос

I have a text file stored on a ftp account. I have the hostname, username and the password. I dont know what is the name of the file, but i know that on root there is only 1 file. I have to read that file line by line and store that content into a php variable.

This is what i have tryed:

$ftp_server = "myhostname";
$conn_id = ftp_connect($ftp_server);
$ftp_user_name = "myusename";
$ftp_user_pass = "mypassword";
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);


if ((!$conn_id) || (!$login_result)) { } 
else {  
ftp_pasv( $conn_id, true ); 

    $contents = ftp_nlist($conn_id, ".");   

    $filename = $contents[0]; //name of the file

    $handle = fopen($filename, "r");
    $file_content = fread($handle, filesize($filename));        
    print_r($file_content);         

}

I run this script from my localhost, but it seems it trys to read a file stored in the same folder where is this php file insted of reading from the ftp server.

Это было полезно?

Решение

You need to download a file from FTP with ftp_get first and then fopen and fread on local machine.

http://php.net/manual/en/function.ftp-get.php

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top