Hello friends, I have an web application that shows some excel reports that users can download from the ftp server. The number of reports users can download can be anywhere from 1 to 25. As its painfull to download each file at a time, I provided a link so that users can download all the reports into one single excel file when they click this link. But when I click on this link only one file (with multiple work sheets) is downloaded and written to the excel file but does not write the contents of other files. Here is my code (I tried to format the code but could not) --
for (int i = 0; i < fileNames.size(); i++) { ftp.connect(p.getSetupParameters("FTPSERVERNAME")); ftp.login(p.getSetupParameters("FTPUSERNAME"), p.getSetupParameters("FTPPASSWORD")); fileName = fileNames.get(i).toString(); String fname = fileName.substring(fileName.lastIndexOf("/") + 1);
if (fileName.substring(fileName.lastIndexOf(".") + 1).toUpperCase().equals("ZIP")) { ftp.setFileType(FTPClient.BINARY_FILE_TYPE); } else if (fileName.substring(fileName.lastIndexOf(".") + 1).toUpperCase().equals("XLS")) { ftp.setFileType(FTPClient.BINARY_FILE_TYPE); } else { ftp.setFileType(FTPClient.ASCII_FILE_TYPE); } ftp.changeWorkingDirectory(path);
InputStream is = ftp.retrieveFileStream(fname); if (ftp.getReplyCode() != 550) { Logger.log("INFO", this, "Successful File Retrieval"); } else { ftp.disconnect(); continue; } int x; if (ftp.getReplyCode() != 550 && reportFormat.equals("XLS")) { while ((x = is.read()) > -1) { out.write(x); } is.close(); } ftp.disconnect(); } out.flush(); out.close(); }
Any help will be appreciated.
Thanks, Ajay
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 32769
posted
0
Not following at all. The user clicks on a link, and then that code is executed, on the server? It looks like the code is downloading something. How does that help a remote user obtain a file? Obviously, I'm missing something.
Basically my question comes down to, how can I download multiple excel files into one big excel file. On my web page I show the user a bunch of excel files. By clicking on a link all the check boxes next to the files get checked and should start downloading into one big file.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 32769
posted
0
You can't download several files and have them magically appear as one. You can create a single file on the server (using POI or jExcel; see Accessing File Formats in my signature) which can then be streamed to the user.
Ajay Reddy
Ranch Hand
Joined: Apr 08, 2005
Posts: 43
posted
0
The solution for this is to zip up all the files together. I can only think of this as solution.
subject: Creating one excel from from multiple excel files