Download multiple files from ftp location from ajax call through servlet/java - java

I have files inside folders at ftp location. I want to download multiple files from web application through ajax call.
Tried one way that copy to server from ftp and converting to zip and then download but i dont want to download to server. Is there anyway i can directly download form ftp.
Thanks in advance,

if using apache FTP client on the java server you can retrieveFileStream(path) and then iterate the inputstream and write to the HttpServletResponse

Related

Java - Best way to send or upload and retrieve files to a server within a network?

I'm currently developing a Tracking System with JavaFX and MySQL as database that is kept in a server. My application is used within a network and allows users to upload and download pictures and several types of document.
My question: What is the best way to send and retrieve files to a server within a network? And should I store those files in MySQL or just their paths in MySQL? If only files' paths, do I need FTP or other techniques? I need detail answer because it is my first time to develop such application.
Edit: I want to store data in a server. I build this application for client machines so that clients can keep documents in the server and they can access their files from any machines... I have no idea for how to transfer files from client machines to server. Please help me!
You should use socket programming like what is at following link:
http://www.rgagnon.com/javadetails/java-0542.html
.But if you are using Java7, Files is the best one instead of BufferedInputStream or FileInputStream (No extra library require):
/* You can get Path from file also: file.toPath() */
Files.copy(InputStream in, Path target)
Files.copy(Path source, OutputStream out)

How can you download/export an object in JSP to a file stored remotely?

I'm using JSP and I have a complex serializable object that I want to be downloaded into a flat file format to the client computer. How can this be done?
I can get the object to save locally to the JSP server using ObjectOutputStream but I need the object to be stored remotely to the JSP server and never locally (e.g. to the clients storage)
Once the object is stored on the clients computer locally, I then want to be able to upload it back to the JSP server and opened/read into an object, how can this be done?
Kind Regards,
Tim
I think, it is not possible for a JSP server to write automatically to a network location. This is a security restriction and may not be possible without a manual request to application. You may want to use below strategies:
Create a shared location at client machine (assuming, it is on network) and mount the location on your server, then code the JSP to save the file at that location.
Save the file on JSP server location, then an FTP transfer script can be written to transfer file to client machine; using a job scheduler (needs FTP communication to be established).
Code the application in such a way that it could be downloaded using the application website (like a music file is downloaded). Then at client side, you may run a program, which will connect to the app server and programatically save the file at the client machine.
Your problem is sending a binary object over http.
You can use the following code snippet in the JSP code.
response.setContentType("binary/octet-stream");
response.setHeader("Content-Transfer-Encoding", "binary");
response.setHeader("Content-Disposition","attachment; filename=myjavaobject.obj");
ObjectOutputStream out = new ObjectOutputStream(response.getOutputStream());
oos.writeObject(yourJavaObject); //Assuming yourJavaObject is the java object you want to send.
out.flush();
out.close();
Do not forget to make sure that yourJavaObject is serializable.

GWT - Client-Side File Uploads

I have been messing around with GWT uploads lately. I want to have the ability to upload an XML file from the client, and get the contents of that file (display the contents in a TextArea).
From what I have found on the net, it seems I would have to upload the file to the server, and then get the contents of the file. I do not particularly like the idea of allowing file uploads to the server (even if they are only XML). Is there anyway to pull the contents of a file that the client specifies without sending it to the server?
Thanks
Recent (decent?) browsers implement the "HTML5" File API that's quite easy to use in GWT using JSNI.
See also: https://developer.mozilla.org/en/Using_files_from_web_applications
Because of security restrictions you cannot access the file on the client side alone. It has to be sent to the server for processing.

FTP Upload directory tree in java

Is there any library that supports uploading directory tree in remote server ?
You can always use the org.apache.commons.net.ftp.FTPClient client and recursively upload all files in your directory.
The Apache Virtual File System (VFS) project can do this, whilst abstracting the details of dealing directly with FTP connections.

How to upload and download a directory from FTP server in java?

I am working in a project in which is is require to upload and download a directory and their all the file and folder in java .and I also need to know that uploding and downloading status means how much percent the folder to which I am uploading has been uploaded or downloaded.
You may want to look at the FTPClient class of commons-net as well.
A search for "java ftp client" on google reveals edtFTPj.
Just to throw one more library at you... you could also try Apache Commons VFS. It gives you access to tons of different file systems including FTP.

Categories