PHP - reading FTP file without downloading it/saving it locally -


i ftp files content without saving locally.

this have far:

$ftp_server = "my_server"; $ftp_conn = ftp_connect($ftp_server) or die("could not connect server");  if (@ftp_login($ftp_conn, "username", "password")) {      $local_file = 'c:\users\user\desktop\testing.txt';     $fp = fopen($local_file, "w");      $d = ftp_nb_fget($ftp_conn, $fp, "commands.yml", ftp_binary);      while ($d == ftp_moredata) {         $d = ftp_nb_continue($ftp_conn);     }      if ($d != ftp_finished) {         echo "error downloading $server_file";         exit(1);     }      ftp_close($ftp_conn);     fclose($fp);      $filename = 'c:\users\user\desktop\testing.txt';     $handle = fopen($filename, "r");     $contents = fread($handle, filesize($filename));     fclose($handle);      echo $contents;  } else {     echo "couldn't establish connection."; } 

the code above saves file , read file content. possible read file without saving locally?

from the answer on official php site bob @ notallhere dot com:

don't want use intermediate file? use 'php://output' filename , capture output using output buffering.

ob_start(); $result = ftp_get($ftp, "php://output", $file, ftp_binary); $data = ob_get_contents(); ob_end_clean(); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -