Avatar of ovnadmin
ovnadmin
 asked on

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:
/ftp/user1/
/ftp/user2/
/ftp/user3/
etc

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
</FilesMatch>

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

Thank you for your time.
Web ServersWeb BrowsersLinux

Avatar of undefined
Last Comment
ovnadmin

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
noci

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ovnadmin

ASKER
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.

Noci,

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.
gheist

If it is about downloading - really go with http... Your customers will become 8,3% happier.
noci

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.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ovnadmin

ASKER
Hello,

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!