Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 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.

share|improve this answer
    
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? –  Eye Feb 6 '12 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 '12 at 22:06

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.

share|improve this answer
    
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 –  Eye Feb 3 '12 at 9:26
    
I found mime.types file. It already has "application/x-sh sh". What else should I do? –  Eye Feb 3 '12 at 9:32
    
What software are you using on the server? –  cjc Feb 3 '12 at 10:46
    
vsftpd and Apache. –  Eye Feb 6 '12 at 2:03

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.