NamingException
NamingException

Reputation: 2404

Downloading zip or exe file from SFTP location

Below are the two snippets from my applications and am using J2SSH jar for SFTP access.

first one:

 .........
 .........
 //Open the SFTP channel
 com.sshtools.j2ssh.SftpClient client = sshClient.openSftpClient();
 // writing from source path to outputstream
 client.get("/Repository/Test/index.zip", outputStream);            
 ........
 ........

second one (JSP file):

response.setContentType("application/octet-stream");
response.setHeader("Content-disposition","attachment; filename=index.zip");
BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
client.fillOutputStream(bos);    //  this method calls to first block code.
bos.flush();
bos.close();
response.flushBuffer(); 

everything is working fine in the application without any exceptions. There are no issues when Text files are downloaded. But while am trying to download zip or exe files, something is missing in it. Even the download is getting succesful, the file is not able to extract or not getting executed.

Plz suggest me which might be the problem in it.... especially it should work for exe file...

Upvotes: 1

Views: 1009

Answers (1)

jakcam
jakcam

Reputation: 1929

For this kind of work i use http://commons.apache.org/vfs/

StandardFileSystemManager manager = new StandardFileSystemManager();
FileObject target = manager.resolveFile("file://" + path + File.separator + filenameTarget);
FileObject source = manager.resolveFile(sftpUri + path + File.separator + filenameSource, options);
target.copyFrom(fichierSource, Selectors.SELECT_SELF);

Upvotes: 1

Related Questions