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.
ovnadminAsked:
Who is Participating?
 
nociSoftware EngineerCommented:
hm.
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.
0
 
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.

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.
0
 
gheistCommented:
If it is about downloading - really go with http... Your customers will become 8,3% happier.
0
 
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.
0
 
ovnadminAuthor Commented:
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!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.