2

I have an FTP server (vsftpd) where there are many files of various types. Normally when you click on .tar.gz file in your browser, it starts downloading it.

The problem is when user clicks on .sh file, the file is not downloaded but instead its content is displayed in the browser.

What should I configure FTP or Web server to force it to download .sh files?

Edit: First, Web server is Apache. However, as I understood, Web server doesn't interfere with the request as "ftp://" protocol is used instead of "http://". Perhaps, this is the reason Apache's rules are ignored (because Apache doesn't receive any request). FTP server directly handles all the client requests.

Considering all these. Is there a way to configure FTP server to correctly handle .sh files?

3 Answers 3

3

In Apache, you can do the following to force even the most reluctant of web browsers (I'm looking at you, IE) to download a file:

<FilesMatch *.sh>
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</FilesMatch>

This should be added inside either a VirtualHost, or a Directory within a VirtualHost.

2
  • I'm sure this is a right solution if Web server was handling the requests. However, in my case FTP seems to handle the requests directly. So Apache doesn't seem to be interfering. Is there a way to configure FTP server?
    – esengineer
    Feb 6, 2012 at 2:29
  • Oh, that implementation is entirely up to the browser. I'm not sure you can modify that at all.
    – Kyle Smith
    Feb 6, 2012 at 22:06
0

What web server software are you using?

This is typically taken care of with MIME types. Depending on the web server, you may need to edit the relevant MIME types file (say, /etc/mime.types, or, for nginx, /etc/nginx/mime.types, though that's specified in the /etc/nginx/nginx.conf file) and add in something for the .sh extension.

On Apache, there's a "mime_magic_module". If that's turned on, it will detect that a file is a shell script and set the MIME type to "application/x-shellscript" or "application/x-sh". If your web server doesn't have this sort of auto detection, you can add something like:

application/x-sh               sh

to the equivalent MIME types file.

If you do curl -Iv http://www.example.com/foo.sh you will Content-Type: header indicating what the web server thinks the file it's serving is.

4
  • I got the following. It seems to be seeing the file as binary. But what's then? > Last-Modified: Tue, 31 Jan 2012 19:04:53 GMT > TYPE I < 200 Switching to Binary mode. > SIZE APP-linux.i386.sh < 213 39885273 Content-Length: 39885273 > REST 0 < 350 Restart position accepted (0). Accept-ranges: bytes
    – esengineer
    Feb 3, 2012 at 9:26
  • I found mime.types file. It already has "application/x-sh sh". What else should I do?
    – esengineer
    Feb 3, 2012 at 9:32
  • What software are you using on the server?
    – cjc
    Feb 3, 2012 at 10:46
  • vsftpd and Apache.
    – esengineer
    Feb 6, 2012 at 2:03
-1

If the Web server can add an HTTP header you should be able to pull it off. Something like:

Content-Disposition=attachemnt; filename="abcd.sh"

If the browser speaks FTP directly to the FTP server there isn't a whole lot to tweak.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .