File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes how to copy files form server to local path? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "how to copy files form server to local path?" Watch "how to copy files form server to local path?" New topic
Author

how to copy files form server to local path?

maria edwin
Greenhorn

Joined: Nov 04, 2010
Posts: 10
Hi all,

I need to copy files from server path to local path via signed applet. Could you please advise me how to handle this task.

Regards,
Maria Prabudass
Haina Minawa
Ranch Hand

Joined: Oct 13, 2011
Posts: 119
Hi, do you mean to transfer files from the web server to the client's computer?
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1511
I assume applet is going to be inside a web-page/web-app.
In a web-application, you don't need to write code for bringing something from server to your local, just provide a hyperlink to the file. When the application is run, and you click the link, it will automatically pop-up some message asking whether you want to save or open the file. Yes, thing will be different if you want to upload something from local to server.


Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
Akilesh has give a solution for your problem, but there is another way; writing file through applet in your specific folder. This could be done.

What is it that you want exactly?


Thanks,


Maki Jav


Help gets you when you need it!
maria edwin
Greenhorn

Joined: Nov 04, 2010
Posts: 10
I need to copy the files from "file server"(not from "web server") to local path. I tried via signed applet. But i think "icedtea" plugin need for firefox. Could you please advise any other way for this file coping. Is it possible via Javafx?

Thanks for looking into this.
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
could you show me the java policy file you are using or the directory structure you have or the drive\folder you want to save to?

None of those things that you, are required. I have made an example in 2003 that was an applet and read/wrote to a file on my PC from javaserver.com and geocities site.


simply read file from server and write to the destination file in the folder ie the path you want... Simple I/O.. thats it!


Part of Applet sample code can be

[code]
URLConnection uc = new URL("http:// your server address where servlet will stream out file name and bytes and the url may have get request of file name or send me file request which the servlet will parse ").openConnection();
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setAllowUserInteraction(false);
DataOutputStream dos = new DataOutputStream(uc.getOutputStream());

// The POST line, the Accept line, and
// the content-type headers are sent by the URLConnection.
// We just need to send the request for a specific file or just file as per requirement
dos.writeBytes("SendMeFile".toBytes());
dos.close();

// Read the server response
DataInputStream dis = new DataInputStream(uc.getInputStream());
BufferedReader br = new BufferedReader (new InputStreamReader(dis));
String nextline;
while ((nextline = br.readLine()) != null) {
System.out.println(nextline);
}
dis.close();
br.close();
[/close]

And Server code sample can be in the get or post method can be


request.getParamater();

Do I/O on computer for the requested file or for file request according to your requirement

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class MyServlet extends HttpServlet {

String name = "content.txt"; // Demo text file to send. It could be a binary file like image or c++ compiled file or exe...

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String file = getServletContext( ).getRealPath(name);

res.setContentType("text/plain");// set other content type if required
OutputStream out = res.getOutputStream( );

returnFile(file, out);
}

public static void returnFile(String filename, OutputStream out)
throws FileNotFoundException, IOException {
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(filename));
byte[ ] buf = new byte[4 * 1024]; // 4K buffer
int bytesRead;
while ((bytesRead = in.read(buf)) != -1) {
out.write(buf, 0, bytesRead);
}
}
finally {
if (in != null) in.close( );
}
}
}

Thanks,

Maki Jav
maria edwin
Greenhorn

Joined: Nov 04, 2010
Posts: 10
Thanks for all responses. I could not understand your answer correctly. But my request is download the files from "file server" (not from web server) directly via browser am using "jsp" for login page. I don't know what technologies are supports for this task. I used signed applet. Its working in Internet explorer and chrome but its not support in the Mozilla firefox browser. I have copied my policy file below.


keystore "/home/maria/web/upload/raystore";
grant signedBy "maria" {
permission java.lang.RuntimePermission "WriteFile";
permission java.util.PropertyPermission "user.home", "read";
permission java.io.FilePermission "<<ALL FILES>>", "read, write, delete, execute";
permission java.security.AllPermission;
};

Kindly advise me the ways and solution.

Thanks for looking into this...
Maria prabudass
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1511
Hey Maki and Maria, Why not use the [ c o d e = java ] [ / c o d e ] tags?

maria edwin
Greenhorn

Joined: Nov 04, 2010
Posts: 10
Could you please explain, where i place the code [ code = java ] [ / code ] tags.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

maria, please BeForthrightWhenCrossPostingToOtherSites

http://www.java-forums.org/javaserver-pages-jsp-jstl/52546-how-copy-files-fileserver-local-path-via-browser.html


luck, db
There are no new questions, but there may be new answers.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

maria edwin wrote:But my request is download the files from "file server" (not from web server) directly via browser am using "jsp" for login page. I don't know what technologies are supports for this task.


And what do you mean by a "file server"? What protocol does this file server support? HTTP? FTP? Something else?
maria edwin
Greenhorn

Joined: Nov 04, 2010
Posts: 10
Paul Clapham wrote:
maria edwin wrote:But my request is download the files from "file server" (not from web server) directly via browser am using "jsp" for login page. I don't know what technologies are supports for this task.


And what do you mean by a "file server"? What protocol does this file server support? HTTP? FTP? Something else?



We are maintaining files(doc,zip,image) in the separate server(that is file server) its support http. But web server have full rights to access that "file server". I need to download the files from file server directly(without using temp path) in the client machine.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to copy files form server to local path?
 
Similar Threads
Download data on to local machine
EJB file trasnfer
Copy dlls and lic files from server path to local system 32 dir in Applet init()
newbie question
Not auto deploying into local server