Jump to content

PHP/FTP fopen


jay7981

Recommended Posts

Hey all i am attempting to connect to a ftp address and display the contents of a file into a textarea and i keep getting errors is there something wrong with the code or the ftp server?

 

<?php
    $log_file= "ftp://username:password@68.232.164.100/czero/68.232.164.100:27015/czero/gsconsole.log"; 
    $log_handle = fopen($log_file, "r"); 
    $log_contents = fread($log_handle, filesize($log_file)); 
    fclose($log_handle);
?>
Console Log:
<textarea name="log_view" cols="110" rows="20" readonly="readonly" wrap="virtual"><?php echo "$log_contents" ; ?></textarea>

Link to comment
Share on other sites

Try something like:

<?php
    $log_file= file_get_contents("ftp://username:password@68.232.164.100/czero/68.232.164.100:27015/czero/gsconsole.log"); 

?>
<textarea name="log_view" cols="110" rows="20" readonly="readonly" wrap="virtual"><?php echo $log_file; ?></textarea>

 

You might have to urlencode your URI.

Link to comment
Share on other sites

yes i can access the file via link

 

the errors are

Warning: fopen() [function.fopen]: connect() failed: Connection refused in /home/content/95/6637895/html/example.com/clan_new/includes/functions/test.php on line 13

Warning: fopen(ftp://...@68.232.164.100/czero/68.232.164.100:27015/czero/gsconsole.log) [function.fopen]: failed to open stream: operation failed in /home/content/95/6637895/html/example.com/clan_new/includes/functions/test.php on line 13

Warning: filesize() [function.filesize]: connect() failed: Connection refused in /home/content/95/6637895/html/example.com/clan_new/includes/functions/test.php on line 14

Warning: filesize() [function.filesize]: stat failed for ftp://username:password@68.232.164.100/czero/68.232.164.100:27015/czero/gsconsole.log in /home/content/95/6637895/html/example.com/clan_new/includes/functions/test.php on line 14

Warning: fread(): supplied argument is not a valid stream resource in /home/content/95/6637895/html/example.com/clan_new/includes/functions/test.php on line 14

Warning: fclose(): supplied argument is not a valid stream resource in /home/content/95/6637895/html/example.com/clan_new/includes/functions/test.php on line 15

 

and before i am asked yes i do have read permissions from the server host i emailed them directly and asked if this protocol was allowed and here was there response....

Dear Customer,

Ticket xxx-xxx has been updated by Andrew Miesner [staff].

Jay,

You can absolutely use php and fopen to connect to the FTP and pull the log file. Unfortunately, that would be the only way to do so.

Thank you,
Andrew Miesner
thiersite.com

 

 

Edit:

Attempt of above code failed ...


Warning: file_get_contents() [function.file-get-contents]: connect() failed: Connection refused in /home/content/95/6637895/html/example.com/clan_new/includes/functions/test2.php on line 11

Warning: file_get_contents(ftp://...@68.232.164.100/czero/68.232.164.100:27015/czero/gsconsole.log) [function.file-get-contents]: failed to open stream: operation failed in /home/content/95/6637895/html/example.com/clan_new/includes/functions/test2.php on line 11

Link to comment
Share on other sites

ok so i was able to resolve the connection refused error but the "failed to open stream: No such file or directory" still persisting ...

 

here is the new code:

<?php
$_link = urlencode("ftp://username:password@68.232.164.100") ;
$path1 = "czero" ;
$path2 = urlencode("68.232.164.100:27015") ; 
$log_file = "gsconsole.log" ;
$filename = "$_link/$path1/$path2/$path1/$log_file" ;
    $log_handle = fopen($filename, "r"); 
    $log_contents = fread($log_handle); 
    fclose($log_handle);
?>
<textarea name="Logview" cols="110" rows="20" readonly="readonly" wrap="virtual"><?php echo "$log_contents" ; ?></textarea>

 

the current and persisting errors

Warning: fopen(ftp%3A%2F%2Fusername%3Apassword%4068.232.164.100/czero/test/czero/gsconsole.log) [function.fopen]: failed to open stream: No such file or directory in /home/content/95/6637895/html/example.com/clan_new/includes/functions/test.php on line 16

Warning: Wrong parameter count for fread() in /home/content/95/6637895/html/example.com/clan_new/includes/functions/test.php on line 17

Warning: fclose(): supplied argument is not a valid stream resource in /home/content/95/6637895/html/example.com/clan_new/includes/functions/test.php on line 18

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.