File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes how to download files from a remote server via java code? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to download files from a remote server via java code?" Watch "how to download files from a remote server via java code?" New topic
Author

how to download files from a remote server via java code?

naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 688

finally now i m capable of finding out whether a particular file exits in a remote server or not ..so if i know that
this particular file exits in a remote server what can i do to download that file in my machine ..so for that i need options
like
  • 1 there should be something in java api to download a file from a particular url or absolute path


  • note : both client & server are written in java .

    The Only way to learn is ...........do!
    Visit my blog http://inaved-momin.blogspot.com/
    Tim Moores
    Rancher

    Joined: Sep 21, 2011
    Posts: 2408
    This seems like the same problem we talked about at http://www.coderanch.com/t/556511/java/java/check-whether-file-exits-server, isn't it? So the question is still the same: what protocol does the server understand? For commonly used file transfer protocols like FTP, HTTP, WebDAV and CIFS it's easy to find Java servers. If, OTOH, you're set on implementing your own protocol then you need to write both client and server code for that.
    naved momin
    Ranch Hand

    Joined: Jul 03, 2011
    Posts: 688

    Tim Moores wrote:This seems like the same problem we talked about at http://www.coderanch.com/t/556511/java/java/check-whether-file-exits-server, isn't it? So the question is still the same: For commonly used file transfer protocols like FTP, HTTP, WebDAV and CIFS it's easy to find Java servers. If, OTOH, .

    this is not the same like earlier there i just need to check but here i need to download that file too
    what protocol does the server understand?

    i guess windows pc can transfer file using both ftp & http (ya you are right server running on windows machine)

    you're set on implementing your own protocol then you need to write both client and server code for that


    ya this sounds nice to me (because i guess you are not understanding my problem or what i want to achieve ) here i need to implement a code that does
    every thing first check and then download to my machine
    1st work is done but i need to figure out a way to download a file from server
    so i need to give functionality to the server to check for a file and if exits then send that file to the client (not name but the file itself) i know this is achieve through ftp or http but is there any way in java so that i can download the file from the server
    hope you got it
    if not please ask me again



    Henry Wong
    author
    Sheriff

    Joined: Sep 28, 2004
    Posts: 18542
        
      40

    naved momin wrote:
    Tim Moores wrote:This seems like the same problem we talked about at http://www.coderanch.com/t/556511/java/java/check-whether-file-exits-server, isn't it? So the question is still the same: For commonly used file transfer protocols like FTP, HTTP, WebDAV and CIFS it's easy to find Java servers. If, OTOH, .

    this is not the same like earlier there i just need to check but here i need to download that file too


    The question may be different, but the answer is the same. The other answer was, the server application must do it (check on the file) and then inform the client. This answer is, the server application must do it (check on the file, open the file, and get the data), and then inform the client (the two applications need a protocol to send the data).

    Henry


    Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
    Henry Wong
    author
    Sheriff

    Joined: Sep 28, 2004
    Posts: 18542
        
      40

    naved momin wrote:
    Tim Moores wrote:what protocol does the server understand?

    i guess windows pc can transfer file using both ftp & http (ya you are right server running on windows machine)



    Don't guess. Check it. By default, Windows don't do expose file transfer, unless it is configured. And in some cases, you need to install a third party service.

    Keep in mind, we are talking about the server here. Just because you can run a client that supports ftp and http, doesn't mean that there is a service that will support that protocol when another client tries to connect.

    Henry
    naved momin
    Ranch Hand

    Joined: Jul 03, 2011
    Posts: 688

    Henry Wong wrote:
    naved momin wrote:
    Tim Moores wrote:what protocol does the server understand?

    i guess windows pc can transfer file using both ftp & http (ya you are right server running on windows machine)



    Don't guess. Check it. By default, Windows don't do expose file transfer, unless it is configured. And in some cases, you need to install a third party service.

    Keep in mind, we are talking about the server here. Just because you can run a client that supports ftp and http, doesn't mean that there is a service that will support that protocol when another client tries to connect.

    Henry

    ok i need a protocol to send the information from the server to the client
  • 1 so can we make a ftp protocol in java ..if yes then give me some ideas like first do this or do that etc etc


  • 2 if no ..what should be mine next option to achieve this ?
  • Tim Moores
    Rancher

    Joined: Sep 21, 2011
    Posts: 2408
    I'm not quite sure what you mean by "can we make a ftp protocol in java" - protocols are independent of particular languages. Both FTP client and server implementations are available for Java. Check out Apache Commons Net for the client side, and the Apache Mina FTP server.
    naved momin
    Ranch Hand

    Joined: Jul 03, 2011
    Posts: 688

    Tim Moores wrote:I'm not quite sure what you mean by "can we make a ftp protocol in java" - protocols are independent of particular languages. Both FTP client and server implementations are available for Java. Check out Apache Commons Net for the client side, and the Apache Mina FTP server.


    ok now i have a new way
    when i will send some request to the server the server will open up the ftp.exe program in the system32 folder so what after this step
    there is a command to open a connection between client and server whose syntax is
    but the problem is how i can write that command in a ftp program via code ?? if you can solve my this problem rest i will manage all i am sure this thing will work for sure
    Rob Spoor
    Sheriff

    Joined: Oct 27, 2005
    Posts: 19655
        
      18

    Use an FTP library instead. Apache Commons Net has an FTP client, and I personally use JvFTP whenever I need to access an FTP server from Java.


    SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
    How To Ask Questions How To Answer Questions
    naved momin
    Ranch Hand

    Joined: Jul 03, 2011
    Posts: 688

    Rob Spoor wrote:Use an FTP library instead. Apache Commons Net has an FTP client, and I personally use JvFTP whenever I need to access an FTP server from Java.


    there are plenty of codes written to download a file using Url class but they say this method is not guarenteed to be working for any kind of ftp server ...what does that means
    if my ftp server is filezilla server cant i use URL class to connect to it and use some logic to get the file will this work ?
    or i should go with the JvFTP you suggested but i dont know how to use it
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: how to download files from a remote server via java code?
     
    Similar Threads
    how to check whether a file exits in a server or not ?
    Option tor read FTP file to string variable.
    Case-sensitive of filename
    Batch File
    to upload a file to a remote server on the network