Results 1 to 11 of 11
  1. #1
    ersachinjain is offline Member
    Join Date
    Aug 2009
    Posts
    51
    Rep Power
    0

    Default Download File from the server

    Hi

    I want to write a function in applet which download the excel file from the web server when a button is pressed. I am using a client server architecture in my application.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    This is a forum, not a place to get your work done. So you MUST put some effort first of all. If you stuck on something then ask it here more clearly.

  3. #3
    ersachinjain is offline Member
    Join Date
    Aug 2009
    Posts
    51
    Rep Power
    0

    Default

    Hi

    I actually did try and I am not getting my work done here. I converted a JTable to an excel file on the web server. But now I want to download that file from the server on the local system where the program is running on the server. I would really appreciate the help.

  4. #4
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Show us what you tried, and tell us how it is failing.

    -Gary-

  5. #5
    ersachinjain is offline Member
    Join Date
    Aug 2009
    Posts
    51
    Rep Power
    0

    Default

    Ftp ftp = new Ftp();

    ftp.setLocalDir(new File("C:\\"));
    ftp.setDir("/export/home/project/public_html/meriproject");
    ftp.setBinary();
    ftp.upload(new File("/export/home0/project/meriproject2"));
    ftp.download("results.xls");

    I am using a class FTP which I have imported using a jar file. Now the thing is that this would be used when I am trying to access the the server from a local system. But its the other way around I am trying to dowanload the file from the server to the local system and the code is running on the server.

  6. #6
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Quote Originally Posted by ersachinjain View Post
    Ftp ftp = new Ftp();

    ftp.setLocalDir(new File("C:\\"));
    ftp.setDir("/export/home/project/public_html/meriproject");
    ftp.setBinary();
    ftp.upload(new File("/export/home0/project/meriproject2"));
    ftp.download("results.xls");

    I am using a class FTP which I have imported using a jar file. Now the thing is that this would be used when I am trying to access the the server from a local system. But its the other way around I am trying to dowanload the file from the server to the local system and the code is running on the server.
    Java can't do that (and we wouldn't want it to). Code running on a server can't arbitrarily write files on a client's file system. The client needs to download the file. In this case, it sounds like the client is a web browser, so you either just display a hyperlink and let the user click on it, or you try to automate it with JavaScript (which is not Java, and is outside the scope of this forum).

    -Gary-

  7. #7
    ersachinjain is offline Member
    Join Date
    Aug 2009
    Posts
    51
    Rep Power
    0

    Default

    So you mean there is no way a file can be downloaded on the clients machine. I know that is one of the mail restrictions in applet, but there has to be some way of downloading the file on the system.

  8. #8
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Sure a file can be downloaded, but a server can't make it happen. It has to be done by a client. And if the client is a web browser, that means either the user does it by clicking a link, or it's done in JavaScript.

    -Gary-

  9. #9
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Sorry -- you did say applet, and it is possible for an applet to write to the local file system, as long as it's signed code or uses JNLP.

    JNLP API (The Java™ Tutorials > Deployment > Doing More With Rich Internet Applications)

    -Gary-

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by ersachinjain View Post
    So you mean there is no way a file can be downloaded on the clients machine. I know that is one of the mail restrictions in applet, but there has to be some way of downloading the file on the system.
    You can download files, sure. But you cannot do that in a server. Say you login to the server and try to download a file, then that end works as a client. If you want to download from someone else machine, then your end should work as a client. Server cannot do that.

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Replies: 0
    Last Post: 03-05-2010, 04:21 AM
  2. how to download file from ftp server
    By santhosh_el in forum Networking
    Replies: 0
    Last Post: 11-19-2009, 06:01 AM
  3. Download file from URL?
    By makpandian in forum New To Java
    Replies: 0
    Last Post: 03-10-2009, 12:30 PM
  4. Download from other server
    By javaism in forum Web Frameworks
    Replies: 1
    Last Post: 09-06-2008, 08:24 PM
  5. image download from server
    By willemjav in forum Java Applets
    Replies: 2
    Last Post: 04-03-2008, 10:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •