繁体   English   中英

从SFTP位置下载zip或exe文件

[英]Downloading zip or exe file from SFTP location

以下是我的应用程序中的两个片段,它们正在使用J2SSH jar进行SFTP访问。

第一:

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

第二个(JSP文件):

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(); 

一切正常,在应用程序中没有任何异常。 下载文本文件时没有问题。 但是,在尝试下载zip或exe文件时,其中缺少某些内容。 即使下载成功,文件也无法提取或无法执行。

Plz建议我这可能是问题所在。...尤其是它应该适用于exe文件...

对于这种工作,我使用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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM