gpt4 book ai didi

java - 从 SFTP 位置下载 zip 或 exe 文件

转载 作者:太空宇宙 更新时间:2023-11-04 08:05:09 25 4
gpt4 key购买 nike

下面是我的应用程序中的两个片段,我使用 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 文件时,其中缺少某些内容。即使下载成功,文件也无法提取或无法执行。

请告诉我这可能是其中的问题...特别是它应该适用于 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);

关于java - 从 SFTP 位置下载 zip 或 exe 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12194351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com