Force FTP File Download in Web Browser (VSFTP)

Hi everyone.

Here's my issue:

I have a CentOS 6.6 VSFTP server here setup using virtual user accounts. When users connect to the FTP server and attempt to download a .txt file, .pdf, or other document, their browser opens it in a new tab instead of downloading/saving it. I'd like to force files open in this FTP server to automatically be downloaded, specifically .txt files.

FTP root directory is /ftp, though virtual users are chrooted in their home directories. Directory structure is:

I've followed about a dozen different links of people posting similar issues, mostly related to creating a .htaccess file in the ftp root directory with the following (or similar) contents; however, I've had no success.
<FilesMatch "\.(?i:doc|odf|pdf|rtf|txt)$">
  Header set Content-Disposition attachment

Is there a solution to this problem that will work with VSFTP?

Thank you for your time.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nociSoftware EngineerCommented:
Why not use a webserver to serve out your files.
FTP is actualy a bad protocol, requiring multiple ports, part of which are dynamic, which requires using plain text sessions so a firewall can keep track of those ports.
This causes passwords to be transmitted without encryption. So unless you use anonymous access FTP is bad.

Browsing using ftp make the browser have control on how data should be accessed.
A webserver can (to a certain extend) manipulate tags in the header that indicate how data should be treated. by making it a "binary" data-tag you can make the receiving end "not recognize it" which causes the file-save-as popup to select a filename.

afaik IE. doesn't completely listen to the (mime) tag, but uses the file extension, causing a run for a .txt or .pdf and that causes the file's handler to be activated. Which for a .pdf should f.e. open your file with acrobat reader.
Now if the contents is a windows executable, with .pdf in the name, that might get the program be executed in stead of acrobat reader....

So short version: use web server (best with https access, for security & privacy), and try to force a binary mime-tag on a transfer and avoid IE on the client side.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ovnadminAuthor Commented:
So short version: use web server (best with https access, for security & privacy), and try to force a binary mime-tag on a transfer and avoid IE on the client side.


Unfortunately, we cannot use a web server for this application as this FTP server is integrated with our product line and used by those products in the field. In this particular case, I need users at a remote location to have access to a single text file. FTP and works well with the added step of right clicking the link and selecting "save link as" on the document that's needed. I'm just trying to simplify the download process a bit.
If it is about downloading - really go with http... Your customers will become 8,3% happier.
nociSoftware EngineerCommented:
sorry the ftp server cannot influence the browser to have a different view on the downloaded file.
Changing the extension to .bin might help, in that case the users need to rename the file locally.
ovnadminAuthor Commented:

Unfortunately, we were not able to force file downloads via FTP in the web browser, so, as you suggested, we rebuilt this solution as a web server and used apache to host the files that were needed.  

Thanks again for your advice!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.