Downloading a Zip file from FTP location using FileDownloader & StreamResou

Hi All,

So basically, I have to perform the action specified in the heading. To elaborate, I have a FTP server where I have a couple of zip files and in my application those files are displayed in a table using the ftpclient. Also I have a download button, on click of this button the selected zip file from the table is to be downloaded on the user’s local machine.

This is the code for downloading the file. The first zip file gets downloaded smoothly. For the second file, the stream is not getting updated i.e. the first file only gets downloaded or the connection is timed out.

private StreamResource createResource() {

for (final String pkgName : SEL_PACKAGE_NAMES) {
return new StreamResource(new StreamSource() {
private static final long serialVersionUID = 2592872436869249225L;

@Override
public InputStream getStream() {
InputStream is = null;
try {
is = new BufferedInputStream(ftpHelper.getFTPClient().retrieveFileStream(pkgName));
} catch (final IOException e) {
e.printStackTrace();
} finally {
try {
} catch (final IOException e) {
e.printStackTrace();
}
}
return is;

}
}, pkgName);

}

return null;

}

This is the code for the button click event :

public void buttonClick(final ClickEvent event) {
for (final String pkgName : SEL_PACKAGE_NAMES) {
try {
res = createResource();
downloader = new FileDownloader(res);
downloader.extend(downloadBtn);

} catch (final Exception e) {
e.printStackTrace();
}
}
}

});

Any help or alternative is welcome!
Thanks in advance! :slight_smile: