PHP remote access to .htaccess protected files

I'm having a bit of trouble trying to access the content of .txt files on a remote server that are in an .htaccess protected directory.

What I am trying to do is the following:

  • Connect to the FTP server via PHP and use ftp_nlist to retrieve a list of all the .txt files in a directory. Up to here, everything works fine.

  • For each .txt file found, I want to retrieve the contents. There are a number of ways to do this normally which all work fine when there is no .htaccess file protecting the .txt files.

BUT! As soon as I protect the online directory with the .htaccess file, every single method I have tried fails to get the contents of the .txt files. The .htaccess file that is protecting the folder that contains the .txt files has the following (and nothing else):

<Files *.txt> 
Order Deny,Allow  
Deny from All  
</Files>

Obviously, the online PHP website itself can access the contents of the .txt files without any problems, and the .htaccess file itself is doing it's job perfectly (denying direct access to any of the files), but when I'm trying to access the .txt files remotely from my WAMP server, I just can't find a way to bypass the .htaccess protection.

Basically, I want to imitate remotely, from my WAMP server, what my website already does itself locally by using $contents = file($filepath). Surely there must be a way... Can anyone point me in the right direction? Should I be using a different method of protecting the .txt files, or should I be using a specific PHP function to access the contents?

Answers


Your question isn't clear. If you protect a folder or a file with .htaccess you will be still able to download that file with FTP. .htaccess affects only Apache (http requests).

If you want to be able to download those file anyway with http, then you just do a script that outputs its content:

downloader.php:

    //> Check if the admin is logged, and check if $_GET['filename'] is allowed

    readfile($_GET['filename']);

Then you can request your file with:

http://yoursite/downloader.php?filename=file.txt

Of course be sure to protect the access of this downloader.php


Need Your Help

How to build this project?

linux macos unix makefile gnu-make

I've been a visual studio developer for long and just trying to understand how things are in linux/unix worl. I found an open source project (Gcomandos) in source forge and tried to build it. when I