我有这个简单的构建脚本:
import org.ajoberstar.grgit.Grgit
apply plugin: 'application'
apply plugin: 'org.ajoberstar.release-opinion'
task wrapper(type:Wrapper) {
gradleVersion = '2.1'
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.ajoberstar:gradle-git:0.11.+'
}
}
release {
grgit = Grgit.open(project.file('.'))
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个HelloWorld样式项目并初始化了git存储库.当我使用远程原点的目录时,我可以运行
.\gradlew.bat release
Run Code Online (Sandbox Code Playgroud)
正好.但是当我使用ssh目标作为远程原点时,我得到以下输出:
16:39:55.355 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter] Executing actions for task ':prepare'.
16:39:55.355 [INFO] [org.gradle.api.Task] Fetching changes from remote: origin
16:39:55.387 [INFO] [org.ajoberstar.grgit.auth.TransportOpUtil] The following authentication options are allowed (though they may not be available): [
HARDCODED, PAGEANT, SSHAGENT, INTERACTIVE]
16:39:55.402 [INFO] [org.ajoberstar.grgit.auth.TransportOpUtil] using interactive credentials, …
Run Code Online (Sandbox Code Playgroud) import com.jcraft.jsch.*;
public class App {
public static void main(String args[]) {
JSch jsch = new JSch();
Session session = null;
try {
session = jsch.getSession("Username", "Host", PORT NO);
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword("Password");
session.connect();
Channel channel = session.openChannel("sftp");
channel.connect();
ChannelSftp sftpChannel = (ChannelSftp) channel;
sftpChannel.get("remotefile.txt", "localfile.txt");
sftpChannel.exit();
session.disconnect();
} catch (JSchException e) {
e.printStackTrace();
} catch (SftpException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
我不想要这个sftpChannel.get("remotefile.txt","localfile.txt");
我只想创建两个方法1)将文件从远程位置复制到本地系统2)以删除sftp连接中复制的文件
谁能帮忙..
Java - Jsch sudo命令.
我正在使用Jsch,我的任务是登录服务器并运行命令,如下所示
sudo su - bumboo
Run Code Online (Sandbox Code Playgroud)
使用以下代码我成功连接,但当我尝试运行命令时,它给了我错误 sudo: sorry, you must have a tty to run sudo
以下是我的代码
public static Channel sudoBamboo(Session session, String sudo_pass) throws Exception {
ChannelExec channel = (ChannelExec) session.openChannel("exec");
//SUDO to bamboo user
String command = "sudo su - bumboo";
channel.setCommand(command);
//InputStream in = channel.getInputStream();
channel.setInputStream(null, true);
OutputStream out = channel.getOutputStream();
//channel.setErrStream(System.err);
channel.setOutputStream(System.out, true);
channel.setExtOutputStream(System.err, true);
//Test change
//channel.setPty(false);
channel.connect();
out.write((sudo_pass + "\n").getBytes());
out.flush();
return channel;
}
Run Code Online (Sandbox Code Playgroud)
他们建议使用sudo.java中的jsch
// man sudo
// -S …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用JSCH库版本0.1.49连接到SFTP远程服务器.每次运行程序时,都会收到以下错误:
Initializing...
Connection to SFTP server is successfully
com.jcraft.jsch.JSchException: Unable to connect to SFTP server.com.jcraft.jsch.JSchException: failed to send channel request
at shell.MainClass.JschConnect(MainClass.java:95)
at shell.MainClass.main(MainClass.java:30)
Run Code Online (Sandbox Code Playgroud)
第30行是:sftpChannel.connect()
从下面的代码:
System.out.println("Initializing...");
JSch jsch = new JSch();
Session session = null;
try {
session = jsch.getSession(ProjectConstants.rmUsername,ProjectConstants.rmHost, 22);
session.setPassword(ProjectConstants.rmPassword);
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
if (session.isConnected() == true) {
System.out.println("Connection to SFTP server is successfully");
}
ChannelSftp sftpChannel = (ChannelSftp) session.openChannel("sftp");
try {
sftpChannel.connect();
} catch (Exception e) {
throw new …
Run Code Online (Sandbox Code Playgroud) 当下面的代码完成运行时,netstat -a|grep sftp
显示一个打开的SFTP连接.它也显示为JProfiler中的开放连接.
channel.isConnected()
在finally块中打印false.任何想法为什么连接没有被关闭,因为我不知所措?
public static void clean() {
com.jcraft.jsch.ChannelSftp channel = null;
try {
channel = Helper.openNewTLSftpChannel();
channel.connect();
channel.cd(remoteFileDirectory);
List<ChannelSftp.LsEntry> list = channel.ls("*." + fileType);
for (ChannelSftp.LsEntry file : list) {
String fileName = file.getFilename();
DateTime fileDate = new DateTime(parseDateFromFileName(fileName));
//if this file is older than the cutoff date, delete from the SFTP share
if (fileDate.compareTo(cleanupCutoffdate) < 0) {
channel.rm(fileName);
}
}
} catch (Exception exception) {
exception.printStackTrace();
} finally {
if …
Run Code Online (Sandbox Code Playgroud) 我的目标是连接到防火墙后面的服务器(主机).我可以通过连接到网络中的另一个服务器(隧道)然后SSH到此服务器来访问此服务器.但是我无法通过JSch实现相同的场景.
我无法使用以下代码工作,我为此目的编写了这些代码.如果我在这里做任何蠢事,请告诉我.
public class JschExecutor {
public static void main(String[] args){
JschExecutor t=new JschExecutor();
try{
t.go();
} catch(Exception ex){
ex.printStackTrace();
}
}
public void go() throws Exception{
StringBuilder outputBuffer = new StringBuilder();
String host="xxx.xxx.xxx.xxx"; // The host to be connected finally
String user="user";
String password="passwrd";
int port=22;
String tunnelRemoteHost="xx.xx.xx.xx"; // The host from where the tunnel is created
JSch jsch=new JSch();
Session session=jsch.getSession(user, host, port);
session.setPassword(password);
localUserInfo lui=new localUserInfo();
session.setUserInfo(lui);
session.setConfig("StrictHostKeyChecking", "no");
ProxySOCKS5 proxyTunnel = new ProxySOCKS5(tunnelRemoteHost, 22);
proxyTunnel.setUserPasswd(user, password); …
Run Code Online (Sandbox Code Playgroud) 在Maven中settings.xml
,我想定义一个SSH服务器并提供:
我不想:
~/.ssh/known_hosts
文件因此,StackExchange上的现有答案对我没有帮助,其中包括:
NullKnownHostProvider
和设置hostKeyChecking
为no
.~/.ssh/known_hosts
文件中输入的hostkey.这是我如何设想它可以在maven中设置的一个例子setup.xml
:
<servers>
<server>
<id>gitcloud.myserver.net:8001</id>
<username>git</username>
<privateKey>C:/data/home/.ssh/id_rsa</privateKey>
<configuration>
<knownHostsProvider implementation="org.apache.maven.wagon.providers.ssh.knownhost.SingleKnownHostProvider">
<hostKeyChecking>yes</hostKeyChecking>
<contents>codecloud.web.att.com ssh-rsa XXXXA3NvvFakeSSHKEYsdfADA...doLQ==</contents>
</knownHostsProvider>
</configuration>
</server>
</servers>
Run Code Online (Sandbox Code Playgroud) 我下载了一个新的JSch 0.1.53库,并且JSch(sftp)下载任务不再有效.此版本在session.connect()
函数抛出错误时失败Session.connect: java.io.IOException: End of IO Stream Read
.
我的旧jsch.jar(2011-10-06)对同一主机工作正常,也许我错过了一个新的配置道具?
Session session=null;
ChannelSftp channel=null;
try {
JSch.setLogger(SSHUtil.createJschLogger());
JSch jsch=new JSch();
session=jsch.getSession("myuser", "11.22.33.44", 22);
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword("mypwd");
session.connect(2000); // <-- FAILS HERE
channel = (ChannelSftp)session.openChannel("sftp");
channel.connect(2000);
...
Run Code Online (Sandbox Code Playgroud)
这是一个广泛的JSch日志记录,表明正在进行什么.
INFO : Connecting to 11.22.33.44 port 22
INFO : Connection established
INFO : Remote version string: SSH-2.0-OpenSSH_6.6.1
INFO : Local version string: SSH-2.0-JSCH-0.1.53
INFO : CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
INFO : aes256-ctr is not available.
INFO : aes192-ctr is not …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用jgit的api使用以下代码执行git pull/push
org.eclipse.jgit.api.Git.open(theRepoFile).pull().call()
Run Code Online (Sandbox Code Playgroud)
但我得到例外
JSchException Auth fail
com.jcraft.jsch.Session.connect (Session.java:461)
org.eclipse.jgit.transport.JschConfigSessionFactory.getSession (JschConfigSessionFactory.java:116)
org.eclipse.jgit.transport.SshTransport.getSession (SshTransport.java:121)
org.eclipse.jgit.transport.TransportGitSsh$SshPushConnection.<init> (TransportGitSsh.java:306)
org.eclipse.jgit.transport.TransportGitSsh.openPush (TransportGitSsh.java:152)
org.eclipse.jgit.transport.PushProcess.execute (PushProcess.java:130)
org.eclipse.jgit.transport.Transport.push (Transport.java:1127)
org.eclipse.jgit.api.PushCommand.call (PushCommand.java:153)
Run Code Online (Sandbox Code Playgroud)
即使使用cgit pull and push工作.
我尝试检查SO以获取示例代码
但上面的问题没有提供一个完整的编码示例,说明使用通常通过ssh密钥进行身份验证的远程仓库执行git pull所需的操作.应该有一种方法来获取凭证信息~/.ssh/
或等效的窗口.
在尝试在ant
包含scp
任务的Eclipse中执行目标时,我收到错误
BUILD FAILED
D:\Users\Dims\Design\liferay-plugins-sdk-6.1.1-tomcat-6.0.37-x64-liferay-6.1-GA2\portlets\scisbo-portlet\build.xml:11: Problem: failed to create task or type scp
Cause: Could not load a dependent class com/jcraft/jsch/Logger
It is not enough to have Ant's optional JARs
you need the JAR files that the optional tasks depend upon.
Ant's optional task dependencies are listed in the manual.
Action: Determine what extra JAR files are needed, and place them in one of:
-D:\APPS\eclipse-liferay-ide\plugins\org.apache.ant_1.8.2.v20120109-1030\lib
-C:\Users\dims\.ant\lib
-a directory added on the command line with the -lib argument …
Run Code Online (Sandbox Code Playgroud)