jay7981 Posted February 25, 2011 Share Posted February 25, 2011 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> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 25, 2011 Share Posted February 25, 2011 What are the errors? Ken Quote Link to comment Share on other sites More sharing options...
requinix Posted February 25, 2011 Share Posted February 25, 2011 That's an awfully repetitive URI you have there. Quote Link to comment Share on other sites More sharing options...
angelcool Posted February 25, 2011 Share Posted February 25, 2011 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. Quote Link to comment Share on other sites More sharing options...
angelcool Posted February 25, 2011 Share Posted February 25, 2011 BTW, first make sure you can access that log file using the link. Copy and paste it in your browser to find out. Quote Link to comment Share on other sites More sharing options...
jay7981 Posted February 25, 2011 Author Share Posted February 25, 2011 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 Quote Link to comment Share on other sites More sharing options...
jay7981 Posted February 25, 2011 Author Share Posted February 25, 2011 That's an awfully repetitive URI you have there. Yes i know but unfortunatly i cant change that its set via the host ..... Quote Link to comment Share on other sites More sharing options...
jay7981 Posted February 25, 2011 Author Share Posted February 25, 2011 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 Quote Link to comment Share on other sites More sharing options...
jay7981 Posted February 25, 2011 Author Share Posted February 25, 2011 in the pitiful voice of a 5 year old .... HELP! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.