我执行很多scp和sshexec从一个Ant构建脚本和其他远程命令.如果jsch.jar不在ant lib目录中,这些命令不起作用.为了使它工作,我将JAR复制到ant lib目录中,但这不是一个好的解决方案,因为任何想要运行脚本的人都必须做同样的事情.要从Teamcity运行ant目标,我们必须显式设置lib文件的路径.
有没有办法可以在ant build XML本身中指定JAR的路径?
有人可以告诉我ChannelExec&之间的区别ChannelShell吗?
我在我的本地Windows 7机器上安装了FileZilla FTP Server.我还在同一台机器上安装了FileZilla FTP客户端.两者之间的连接成功,确认服务器和客户端伙伴关系存在.
我写了一个简单快捷的Jsch程序,用于连接FileZilla FTP服务器,下面是程序:
public class TestJSch {
/** Creates a new instance of TestCommonsNet */
public TestJSch() {
}
/**
* main - Unit test program
*
* @param args
* Command line arguments
*
*/
public static void main(String[] args) {
try {
String ftpHost = "127.0.0.1";
int ftpPort = 21;// 14147;
// int ftpPort = 990;// 14147;
String ftpUserName = "kedar";
String ftpPassword = "XXXXXXXXXXX";
String ftpRemoteDirectory = "C:\\KEDAR\\Java\\FTP_Folder";
String fileToTransmit = "C:\\KEDAR\\Java\\File_Folder\\Customer.txt";
String …Run Code Online (Sandbox Code Playgroud) 我用java编写的git客户端遇到了一些困难.我正在使用jGit库通过git服务器上的ssh进行连接.问题是我不知道如何指定私钥的路径和密码.我在jGit文档中找不到有关我需要调用哪些函数的任何示例.从我读到的jGit库使用JSch使用ssh连接到服务器,JSch支持私钥和密码.有没有人有这方面的经验或有一些工作代码?
谢谢
如何在使用JSCH SFTP API创建新目录之前检查目录是否存在?我正在尝试使用,lstat但不确定它是否正在完成我需要的工作.谢谢你提前
我是使用Apache Common vfs的新手,我成功连接到我已经阅读过docs的服务器但是我坚持使用这段代码.我如何列出目录/文件?
....
Session session = null;
FileSystemManager fsManager = null;
FileSystem fs = null;
try {
String host = "host_here";
int port = 22;
String userStr = "user_here";
char [] username = userStr.toCharArray();
String passStr = "password_here";
char [] password = passStr.toCharArray();
session = SftpClientFactory.createConnection(host, port, username, password, null);
//session.connect();
System.out.println("Connected to the server");
FileSystemOptions opts = new FileSystemOptions();
fsManager = VFS.getManager();
FileObject file = fsManager.resolveFile("ftp://"+userStr+":"+passStr+"@"+host+"/home/", opts);
// .... whats next i do here? .....
} catch (Exception …Run Code Online (Sandbox Code Playgroud) 我正在使用JSch 0.1.50为我的CI Jenkins插件建立与远程服务器的连接.让我们假设我在这里使用session.connect(60000);超时60秒:
Session session = null;
try {
JSch jsch = new JSch();
if (rsaIdentity != null && !rsaIdentity.equals("")) {
jsch.addIdentity(rsaIdentity.trim());
}
session = jsch.getSession(serverLogin, serverHost, Integer.parseInt(serverPort));
session.setPassword(getDescriptor().getOpenPassword(encryptedPasswordString));
session.setConfig("StrictHostKeyChecking", "no"); // not use RSA key
int timeOut = Integer.parseInt(getDescriptor().getConnectionTimeOut());
session.connect(60000);
} catch (SocketTimeoutException e) {
logger.error(e.getMessage());
return false;
} catch (JSchException e) {
logger.error(e.getMessage());
return false;
}
Run Code Online (Sandbox Code Playgroud)
但实际上在连接到相当慢的服务器期间执行此代码期间,我Exception每次都会在大约20秒内面临超时:
2016-01-25 13:15:55.982 [INFO] Connecting to server: devsrv26:22 as [user] ...
2016-01-25 13:16:16.991 [ERROR] java.net.ConnectException: Connection timed out: …Run Code Online (Sandbox Code Playgroud) 我实现了一个Java程序,该程序将使用JSCH在远程服务器中连接并执行命令。问题是,每当我尝试连接到服务器时,都会出现以下异常:
com.jcraft.jsch.JSchException: Session.connect: java.security.InvalidAlgorithmParameterException: Prime size must be multiple of 64, and can only range from 256 to 2048 (inclusive)
Run Code Online (Sandbox Code Playgroud)
我尝试了在jre / lib和security.provider中添加Bouncy Castle提供程序的解决方案,它可以正常工作。但是我需要使其依赖于项目,因此我尝试在构建路径中添加Bouncy Castle,并在程序中手动添加Bouncy Castle提供程序。但是将其导出到jar后,我仍然收到异常。
package services;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.security.Security;
import java.util.Iterator;
import java.util.Properties;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public class MainService {
public MainService() {
Security.addProvider(new BouncyCastleProvider()); //Adding BouncyCastlePRovider in security
// TODO Auto-generated constructor stub
String report = "";
StringBuilder sb = new StringBuilder();
System.out.println("Running the monitoring...");
System.out.println("Starting printer monitoring...");
PrinterService ps = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Kotlin + JSch 建立 SSH 连接,但失败并显示
\n\n\ncom.jcraft.jsch.jSchException:身份验证失败
\n
采取的步骤:
\nssh-keygen -t rsa -m PEM使用(OpenSSH 版本OpenSSH_8.2p1:)生成 SSH 密钥对id_rsa.pub到/home/username/.ssh/authorized_keys服务器上的文件中ssh -i /path/to/id_rsa username@example.host.com\xe2\x80\x93 工作正常import com.jcraft.jsch.JSch\n\nconst val USER = "username"\nconst val HOST = "example.host.com"\nconst val IDENTITY = "/path/to/id_rsa"\n\n\nfun main() {\n val jsch = JSch().apply {\n addIdentity(IDENTITY)\n setKnownHosts("/path/to/known_hosts")\n }\n\n jsch.getSession(USER, HOST)\n .connect()\n}\nRun Code Online (Sandbox Code Playgroud)\n...失败但有异常:
\nimport com.jcraft.jsch.JSch\n\nconst val USER …Run Code Online (Sandbox Code Playgroud)