I don't know which forum to post this under. I already posted under the I/O forum. I'm trying to create a JSP that would let the user select a file from local system and upload it to a remote system and let the user download an uploaded file later. The remote server is an SFTP server.
My code was running fine (both upload and download) while i was testing on the local system (tomcat running on my system, and I'm selecting files from my system). But when the code was deployed on the actual testing servers, the code started failing with FileNotFoundException. I realised that the filename that I was sending to the code from the <input type="file"> field was not enough as my code would look for the file on the server. Same while downloading.
This is SFTP, so I can not use the regular FTP related code samples. I used the APIs from JSCH and code samples from Tim Archer's website.
Everything worked fine as long as the file was being uploaded from the server on which the code was running and/or the file was being downloaded to the server.
Can anyone please let me know if there is a way to use streams to send the data from the client filestream and make the code on the server use that stream instead of looking for the file on the server.
Any help is highly appreciated. This is very urgent for me!
Please do not post the same question to multiple forums: CarefullyChooseOneForum. I have deleted the other copies of your post.
Servlets/JSPs only support file upload and download through HTTP. So you need to receive the file on the server through an HTTP file upload, using a library like Apache Commons FileUpload. Then you can move it to some other server using whatever protocol is appropriate. Same for downloading - you need to get the file from the other server to the server running the servlet container first; then you can stream it to the client using HTTP.
(As as aside, you really should not use JSPs for I/O operations -or any kind of processing-, use a servlet instead.)
OK, I edited the title. Sorry about that....
You need to be a little forgiving to the "Greenhorns"
But anyway, will definitely take care of this in future...
Coming back to the topic then, can you please direct me to some good code samples that specifically show the upload and downloading of the files to and from the server and specifically handling the location (as in where it will end up when uploading or downloading). I did look up on the web and there are many code samples for multipart/form-data type but most of them are not working for me.
Some code samples will really help me right now as the actual obstacle of JAVA - SFTP is not a problem for me anymore. I just need to get the file from the client to the server now and vice versa for download as you suggested.
The online documentation has some simple code examples that make it easy to get going.
For downloading files, the SimpleStream demo app in our codebarn shows how to stream a file from within a web application's directory structure. If you are uploading to a directory outside of the web application's directory structure (best practice) then you would need to modify the SimpleStream app to read the file using java.io.FileReader.