• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to copy files form server to local path?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, do you mean to transfer files from the web server to the client's computer?
 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
maria edwin
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Maki and Maria, Why not use the [ c o d e = java ] [ / c o d e ] tags?

 
maria edwin
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you please explain, where i place the code [ code = java ] [ / code ] tags.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
maria, please BeForthrightWhenCrossPostingToOtherSites

http://www.java-forums.org/javaserver-pages-jsp-jstl/52546-how-copy-files-fileserver-local-path-via-browser.html
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic