gpt4 book ai didi

java - Java FTP 库 Jsch 的问题

转载 作者:行者123 更新时间:2023-12-02 02:14:20 38 4
gpt4 key购买 nike

我使用的是 Java 1.7、jsch 0.1.54 和 commons-vfs2 2.1。

这是我正在使用的代码:

JSch.setConfig("kex", "diffie-hellman-group1-sha1,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1");
final StandardFileSystemManager manager = new StandardFileSystemManager();

try {
final FileSystemOptions opts = new FileSystemOptions();

FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false);
FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true);

// SSH Key checking
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");
// Root directory set to user home
SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false);

// Timeout is count by Milliseconds
SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, 10000);

manager.init();

for (final FileFTPHelper fileFTPHelper : filesHelper) {

final String filename = fileFTPHelper.getFilename();
final byte[] value = fileFTPHelper.getData();

final String remoteDestination = fileFTPHelper.getRemoteFolder() + filename;

String connection1 = null;
final String userInfo = fileFTPHelper.getUsername() + ":" + fileFTPHelper.getPassword();
URI uri = null;
try {
uri = new URI("sftp", userInfo, fileFTPHelper.getUrl(), fileFTPHelper.getPort(), remoteDestination, null, null);
connection1 = uri.toString();
} catch (final URISyntaxException e) {
throw new ValidationError("Cannot build the URL. Contact your administrator");
}

// Create remote file object
FileObject remoteFile = null;
this.log.trace("Sending file : " + remoteDestination);

try {
this.log.trace(connection1);
remoteFile = manager.resolveFile(connection1, opts);
} catch (final Exception e) {
this.log.error(e, "Error sfp");

}

OutputStream io = null;
if (remoteFile != null) {
remoteFile.refresh();
this.log.trace("Connected ! : " + remoteFile);

try {

io = remoteFile.getContent().getOutputStream();
io.write(value);
io.flush();
io.close();
} catch (final IOException e1) {
} finally {
if (io != null)
try {
io.close();
} catch (final Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
remoteFile.close();
if (!remoteFile.exists())
throw new ValidationError("Issue when sending files over sftp : The file has not been copied on the FTP");

if (!remoteFile.isFile())
throw new ValidationError("Issue when sending files over sftp : The file is not a file");
}
else
throw new ValidationError("Issue when sending files over sftp : Could not resolve file on the FTP");

System.out.println("File upload success");
}
} catch (final Exception e) {
this.log.error(e, "Error");
throw new ValidationError("Issue when sending files over sftp : " + e.getMessage());

} finally {
manager.close();
}

我得到的输出:

SftpClientFactory(line 362) - Connecting to ftpqa.aaaa.com port 22
SftpClientFactory(line 362) - Connection established
SftpClientFactory(line 362) - Remote version string: SSH-2.0-Serv-U_15.1.6.26
SftpClientFactory(line 362) - Local version string: SSH-2.0-JSCH-0.1.54
SftpClientFactory(line 362) - CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
SftpClientFactory(line 362) - aes256-ctr is not available.
SftpClientFactory(line 362) - aes192-ctr is not available.
SftpClientFactory(line 362) - aes256-cbc is not available.
SftpClientFactory(line 362) - aes192-cbc is not available.
SftpClientFactory(line 362) - CheckKexes: diffie-hellman-group14-sha1,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521
SftpClientFactory(line 362) - diffie-hellman-group14-sha1 is not available.
SftpClientFactory(line 362) - CheckSignatures: ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
SftpClientFactory(line 362) - SSH_MSG_KEXINIT sent
SftpClientFactory(line 362) - SSH_MSG_KEXINIT received
SftpClientFactory(line 362) - kex: server: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group14-sha1
SftpClientFactory(line 362) - kex: server: ssh-rsa
SftpClientFactory(line 362) - kex: server: aes256-cbc,rijndael256-cbc,rijndael-cbc@lysator.liu.se,aes256-ctr
SftpClientFactory(line 362) - kex: server: aes256-cbc,rijndael256-cbc,rijndael-cbc@lysator.liu.se,aes256-ctr
SftpClientFactory(line 362) - kex: server: hmac-sha2-256,hmac-sha2-256-96,hmac-sha2-512,hmac-sha2-512-96
SftpClientFactory(line 362) - kex: server: hmac-sha2-256,hmac-sha2-256-96,hmac-sha2-512,hmac-sha2-512-96
SftpClientFactory(line 362) - kex: server: zlib,none
SftpClientFactory(line 362) - kex: server: zlib,none
SftpClientFactory(line 362) - kex: server:
SftpClientFactory(line 362) - kex: server:
SftpClientFactory(line 362) - kex: client: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
SftpClientFactory(line 362) - kex: client: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
SftpClientFactory(line 362) - kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
SftpClientFactory(line 362) - kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
SftpClientFactory(line 362) - kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
SftpClientFactory(line 362) - kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
SftpClientFactory(line 362) - kex: client: none
SftpClientFactory(line 362) - kex: client: none
SftpClientFactory(line 362) - kex: client:
SftpClientFactory(line 362) - kex: client:
SftpClientFactory(line 362) - Disconnecting from ftpqa.aaaa.com port 22

我遇到了以下异常:

  org.apache.commons.vfs2.FileSystemException - Could not connect to SFTP server at "sftp://***:***@ftpqa.aaaa.com/".
org.apache.commons.vfs2.FileSystemException - Could not connect to SFTP server at "ftpqa.aaaa.com".
com.jcraft.jsch.JSchException - Algorithm negotiation fail

我查看了各个网站,算法协商失败似乎与缺少算法有关。我添加了代码 JSch.setConfig("kex", "diffie-hellman-group1-sha1,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman -group-exchange-sha256,diffie-hellman-group14-sha1");但它并没有像你所看到的那样工作。有什么想法吗?

最佳答案

我解决了我的问题,但下载了 Java 加密扩展 (JCE) 无限强度管辖权策略文件 http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html并将它们安装在 java-home\lib\security

关于java - Java FTP 库 Jsch 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49509313/

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