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