2

Below is the code i've written i've to download a file, Now I need to download the file to particular location in client system.I'll get the path through input from the user. I know it's not good to mess client system but I had to do that

        //setting the content type of response
        response.setContentType("application/"+strFileType);

        response.setHeader("content-disposition","attachment; filename="+strFileName+"."+strFileType);

        //creating a file input stream object
         InputStream input = blob.getBinaryStream();

         //declaring a variable
         int i;
         while((i=input.read())!=-1)
         {
             //writing output
             printWriter.write(i);
         }

         //closing the streams
         input.close();
         printWriter.close();
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
sagar
  • 112
  • 9
  • 2
    Can't be done from the server. It would be a big security hole. – madth3 Nov 17 '12 at 05:16
  • seems this is server side code... what you have tried in client side ? – vels4j Nov 17 '12 at 05:23
  • 1
    If you have designed your program in a way that you require this functionality, then you (probably) are either designing malware or have designed your program incorrectly. – Zéychin Nov 17 '12 at 05:23
  • 1
    Wait, if you get the path from input from the user, why wouldn't you just use the path provided by the user? :-\. – Zéychin Nov 17 '12 at 05:24
  • where to use the path taken from the user and i'm programming this just like ftp but server side is a database – sagar Nov 17 '12 at 05:53

3 Answers3

4

I know it's not good to mess client system but I had to do that ....

Well the good news (from the user's perspective!) is that you can't do it. Even if you "have to". A web browser is built specifically to stop you (the server side) from doing that kind of thing.

The only away around this is to implement the functionality in a TRUSTED browser plugin or applet or something that the user has to specifically install on his / her machine.


... where to use the path taken from the user and i'm programming this just like ftp but server side is a database

The problem is that the browser has NO WAY to judge whether you are doing this for legitimate purposes ... or as an attempt to clobber system / user files, plant malware or any number of other things that may be harmful to the user.

It ain't going to take the risk of letting you do it, and that is a GOOD THING.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
1

This needs an update of file download location of browser,[note: if we update this all files will be download to that path]

refer the below links you may get the idea :

How to change the download folder destenation in firefox?

How to check the location of download folder programmatically in browsers like Safari, Firefox etc on Mac?

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/6ff178a2-5131-43d4-b4c0-efb4a2112e95

Community
  • 1
  • 1
Gnanz
  • 1,833
  • 5
  • 24
  • 51
  • *"if we update this all files will be download to that path"* Way to 'disenfranchise' the end-user! *"**note:**"* but +1 for 'note'. ;) – Andrew Thompson Nov 17 '12 at 05:33
0

If you are inside an intranet and can trust a server, use an applet or similar technolofgies with granted access privileges... but once again this is REALLY bad.

Ustaman Sangat
  • 1,505
  • 1
  • 14
  • 26