JSch中每个会话可以打开多少个频道是否有限制?我试图打开的cannels类型为"ChannelShell"
我得到一个"com.jcraft.jsch.JSchException:通道未打开." 当我尝试打开第11个频道即频道[10]这是否意味着每个会话最多可以有10个频道?
PS我不明白如何满足stackoverflow的质量标准.
java 1.8升级后我遇到了一个奇怪的问题.我在我们的一个实用程序中使用jsch-0.1.54.jar从各个地方下载文件.这个特殊的实用程序使用了近4 - 5年没有任何问题(当时jsch-0.1.48).那时环境是java 1.6.最近我们升级到java 1.8,结果我们升级了这个特定的实用程序.现在我们遇到了一个奇怪的问题,它偶尔会发生,大多数时候文件的下载都是完美的.
错误日志
INFO: SSH_MSG_KEXDH_INIT sent
INFO: expecting SSH_MSG_KEXDH_REPLY
INFO: Disconnecting from SRV2000 port 22
2016-10-28 08:42:18:0576 ERROR [main] net.AerisAbstractMethod - Failed to open connection
com.jcraft.jsch.JSchException: Session.connect: java.security.SignatureException: Signature length not correct: got 127 but was expecting 128
at com.jcraft.jsch.Session.connect(Session.java:565)
at com.jcraft.jsch.Session.connect(Session.java:183)
at com.aeris.net.AerisSFTPMethod.connectToServer(AerisSFTPMethod.java:65)
at com.aeris.net.AerisAbstractMethod.getListOfFiles(AerisAbstractMethod.java:143)
at com.aeris.worker.AerisUploaderDownloader.performUploadDownloadListing(AerisUploaderDownloader.java:112)
at com.aeris.main.AerisCommonSftpUtility.main(AerisCommonSftpUtility.java:102)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.simontuffs.onejar.Boot.run(Boot.java:340)
at com.simontuffs.onejar.Boot.main(Boot.java:166)
Run Code Online (Sandbox Code Playgroud)
成功日志:(在大多数情况下,它是成功的)
INFO: SSH_MSG_KEXDH_INIT sent
INFO: expecting SSH_MSG_KEXDH_REPLY
INFO: ssh_rsa_verify: signature …Run Code Online (Sandbox Code Playgroud) 我把Jsch放入了公共池(带有弹簧池支持)并取得了初步成功
http://docs.spring.io/spring/docs/3.2.4.RELEASE/spring-framework-reference/htmlsingle/#aop-ts-pool
然而:
我们应该在会话中汇集频道而不是汇集会话吗?每个Jsch会话创建一个线程.池化Jsch会话将创建x个线程.汇集渠道,实际上只有一个Jsch线程.
(commons-pool)如果Jsch会话变得陈旧会发生什么?如何在commons-pool的上下文中重新生成会话或使用spring pool支持?如何检测它是否陈旧?
谢谢
我的 java 程序使用 ssh/sftp 将文件传输到 linux 机器(显然......),而我这样做的库是 JSch(尽管这不是罪魁祸首)。
现在,其中一些 linux 机器具有 shell 登录启动脚本,这可悲地导致 ssh/sftp 连接失败,并显示以下消息:
收到的消息太长 1349281116
在简要阅读之后,这显然是一个已知的 ssh 设计问题(不是错误 -请参阅此处)。并且所有建议的解决方案都在 ssh 服务器端(即禁用在 shell 登录期间输出消息的脚本)。
我的问题 - 是否可以选择在客户端避免此问题?
所以在我的 scala 类中,我不得不使用 Jsch(JAVA) 库来做 SFTP 工作。但由于某种原因,它无法导入:
import com.jcraft.jsch.ChannelSftp.LsEntry
Run Code Online (Sandbox Code Playgroud)
知道为什么会这样吗?LsEntry 是 ChannelSftp 的嵌套类。
http://epaul.github.io/jsch-documentation/simple.javadoc/com/jcraft/jsch/ChannelSftp.html
package services.impl
import java.nio.file.Path
import com.jcraft.jsch.ChannelSftp
import com.jcraft.jsch.ChannelSftp.LsEntry
import services.InputService
class InputServiceImpl extends InputService[List[ChannelSftp.LsEntry]] {
}
Run Code Online (Sandbox Code Playgroud) 我使用JSch来拖尾远程计算机中的文件.但我发现在程序退出后,"tail -f"进程仍然存在于远程计算机中.如果我删除"-f"参数,一切都OK.
我试过使用"sendSignal()",但它不起作用.似乎OpenSSH没有实现该功能.
这是测试代码.
public static void main(String[] args) throws Exception {
String usr = args[0];
String host = args[1];
String password = args[2];
JSch jsch = new JSch();
Session session = jsch.getSession(usr, host);
String pwd = password;
session.setPassword(pwd);
Hashtable<String, String> config = new Hashtable<String, String>();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect(15000);
session.setServerAliveInterval(15000);
ChannelExec m_channelExec = (ChannelExec) session.openChannel("exec");
String cmd = "tail -f /var/log/messages";
m_channelExec.setCommand(cmd);
InputStream m_in = m_channelExec.getInputStream();
m_channelExec.connect();
BufferedReader m_bufferedReader = new BufferedReader(new InputStreamReader(m_in));
int i = 0;
while (++i …Run Code Online (Sandbox Code Playgroud) 我正在尝试连接到在 Amazon EC2 服务器上运行的 postgres 数据库。我知道服务器配置正确,因为我可以从 pgadmin 访问它并作为 intellij 中的数据源。
当仅使用 jsch 时,我还可以从程序中连接到服务器 shell,并直接使用 jdbc 连接到另一个数据库,但是一旦我尝试通过 ssh 隧道与 jsch 连接到我的 postgres 实例,我就会遇到这个奇怪的错误无法诊断:
org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:262)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:67)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:216)
at org.postgresql.Driver.makeConnection(Driver.java:406)
at org.postgresql.Driver.connect(Driver.java:274)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at EnumStreamer.main(EnumStreamer.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.io.EOFException
at org.postgresql.core.PGStream.ReceiveChar(PGStream.java:285)
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:411)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:208)
... 12 more
Run Code Online (Sandbox Code Playgroud)
我用来连接的代码如下:
System.out.println("Connecting...");
session = secConnect.getSesssion();
UserInfo ui = new uInfo();
session.setUserInfo(ui);
session.connect();
session.setPortForwardingL(5432,secConnect.getHost(),5432);
System.out.println("SSH …Run Code Online (Sandbox Code Playgroud) 我不确定这是否是由于端口转发使用私钥而不是密码引起的,但这是我正在尝试做的
我需要将本地端口 3308 一直转发到我的 SQL 数据库 3306。
我可以在本地的终端中一起运行这样的事情
ssh -L 3308:localhost:3307 username@jumpbox "ssh -L 3307:mysqlDB:3306 username@server"
Run Code Online (Sandbox Code Playgroud)
或者在我的本地运行第一部分,然后在 jumpbox 上运行第二部分。两者都工作正常,我可以连接到我的 localhost:3308。
当我开始使用 JSch 时,问题就来了。这是我的代码
JSch jsch = new JSch();
jsch.addIdentity("~/.ssh/id_rsa");
Session session = jsch.getSession("username", "jumpbox");
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
int assinged_port = session.setPortForwardingL(3308, "localhost", 3307);
Session mysqlSession = jsch.getSession("username", "server", assinged_port);
mysqlSession.setConfig("StrictHostKeyChecking", "no");
mysqlSession.connect(); // Connection timed out here
mysqlSession.setPortForwardingL(3307, "mysqlDB", 3306);
Run Code Online (Sandbox Code Playgroud)
第一个连接已完成,但第二个连接超时。
线程“main”com.jcraft.jsch.JSchException 中的异常:java.net.ConnectException:操作超时(连接超时)
我在 JSch 或端口转发方面做错了吗?
我尝试根据说明在 Java 程序中使用 SSH 与 PythonAnywhere 中的 MySQL 库建立连接: https:
//help.pythonanywhere.com/pages/AccessingMySQLFromOutsidePythonAnywhere
不幸的是,我每次都会遇到这个错误,而且我已经没有想法了:
com.jcraft.jsch.JSchException:拒绝主机密钥:ssh.pythonanywhere.com
public static void main(String[] args) {
Tunnel tunnel = new Tunnel();
try {
tunnel.go();
} catch (Exception e) {
e.printStackTrace();
}
}
public void go() throws Exception {
String host = "ssh.pythonanywhere.com";
String user = "username";
String password = "password";
int port = 22;
int tunnelLocalPort = 9080;
String tunnelRemoteHost = "username.mysql.pythonanywhere-services.com";
int tunnelRemotePort = 3306;
JSch jsch= new JSch();
Session session = jsch.getSession(user,host,port);
localUserInfo lui = …Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用 PGP 加密大文件(我为此使用 BouncyGPG)并使用 SFTP(使用 JSch)将其发送到远程服务器。我正在使用 PipedOutputStream 和 PipedInputStream 来避免在发送到服务器之前将最终加密的文件保存在本地。我相信因此 BouncyGPG 行为不端。
谁能帮我这个?
这是我的代码:
BouncyGPG.registerProvider()
private val bufferSize: Int = 8 * 1024
fun sendFileSFTP(myFile: MyFile {
PipedInputStream().use { input ->
GlobalScope.launch {
PipedOutputStream(input).use { output ->
encrypt(myFile, output)
}
}
sendSFTP(input, "mysftp-directory/${myFile.filename}")
log.info("Finished Sending $myFile")
}
}
fun encrypt(myFile: MyFile output: OutputStream) {
log.info("ENCRYPTING - $myFile")
val pubkey = "/home/myhome/server.gpg"
val privkey = "/home/myhome/server.secret.gpg"
val password = "password"
val keyring = KeyringConfigs.forGpgExportedKeys(KeyringConfigCallbacks.withPassword(password))
keyring.addPublicKey(FileReader(File(pubkey)).readText().toByteArray(charset("US-ASCII")))
keyring.addSecretKey(FileReader(File(privkey)).readText().toByteArray(charset("US-ASCII")))
BouncyGPG.encryptToStream()
.withConfig(keyring)
.withStrongAlgorithms()
.toRecipients("contact@myserver.com")
.andDoNotSign() …Run Code Online (Sandbox Code Playgroud)