鉴于关于scp/ssh和maven的文档很差,我尝试了不同的方法,基本上分为两大类:使用scpexe旅行车和scp旅行车.通常它们在linux和mac上都没有问题,但是在Windows上我从来没有找到让它在所有机器上运行的方法.
scpexe方法(安装完成putty并添加到路径后) - settings.xml配置:
<server>
<id>internal</id>
<username>******</username>
<password>*******</password>
<configuration>
<sshExecutable>plink</sshExecutable>
<scpExecutable>pscp</scpExecutable>
</configuration>
</server>
Run Code Online (Sandbox Code Playgroud)
scp方法 - settings.xml:
<server>
<id>internal</id>
<username>*********</username>
<password>*********</password>
<configuration>
<StrictHostKeyChecking>ask</StrictHostKeyChecking>
</configuration>
</server>
Run Code Online (Sandbox Code Playgroud)
我也尝试将StrictHostKeyChecking设置为"no",但是,除了安全风险之外,在特定机器上无效.
有人找到了在所有机器上一致使用内部ssh存储库的方法吗?
我正在尝试使用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/或等效的窗口.
我正在从Jsch channelSFTP获取输入流,如下所示.
ChannelSftp channelSftp = (ChannelSftp)channel;
InputStream input=channelsftp.get(unixPath);//unixPath is path to my file which is on SFTP server
Run Code Online (Sandbox Code Playgroud)
我必须unixPath在Spring javaMail附件中附加该文件.但是,当我看到Spring JavaMail addAttachment()方法的API时,它只需要InputStreamSource或Datasource.我的问题是我不能够获得InputStreamSource或Datasource从中我得到的形式SFTP channel.How我可以得到InputStream的InputStreamSource或Datasource从上面的InputStream?提前致谢.
我希望能够使用JSch Java SSH库连接到我的EC2实例.如何在AWS中使用AWS的.pem密钥对?尝试连接时如何处理UnknownHostKey错误?
在尝试在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) 我想知道如何使用jgit连接到github使用指定的ssh密钥文件(即不在〜/ .ssh /中).
不幸的是,我不确定如何JschConfigSessionFactory正确使用.我尝试创建一个类似于本文中的设置:使用JGit键来安全地访问Git存储库
我使用git调用git.push().setRemote(remotePath).call();但是,我收到此错误(日志中省略了特定的存储库):
org.eclipse.jgit.api.errors.TransportException: https://github.com/user/repo: not authorized
at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:160)
at gitio.GitInterface.pushToRemote(GitInterface.java:145)
at engine.GitInterfaceTester.main(GitInterfaceTester.java:25)
Caused by: org.eclipse.jgit.errors.TransportException: https://github.com/user/repo: not authorized
at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:479)
at org.eclipse.jgit.transport.TransportHttp.openPush(TransportHttp.java:396)
at org.eclipse.jgit.transport.PushProcess.execute(PushProcess.java:154)
at org.eclipse.jgit.transport.Transport.push(Transport.java:1173)
at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:156)
... 2 more
Run Code Online (Sandbox Code Playgroud)
我注意到JschConfigSessionFactory实际上没有实际调用自定义覆盖方法.这几乎肯定是问题的原因......但不知道为什么不调用它们; 我将自定义传递JschConfigSessionFactory给SshSessionFactory使用SshSessionFactory.setInstance(sessionFactory);
有人知道我做错了什么吗?
我正在尝试使用Java逐行读取文件,这很简单(在stackoverflow.com上有多个解决方案),但需要注意的是该文件位于远程服务器上,而不是可以获得本地副本(它是单个.txt文件中数百万亚马逊评论的大量集合).
JSch附带了两个示例类,用于将文件复制到远程主机或从远程主机复制文件,即ScpTo和ScpFrom.我有兴趣逐行从远程主机读取文件; ScpFrom会尝试将整个内容复制到本地文件中,这需要很长时间.
以下是ScpFrom的链接:http://www.jcraft.com/jsch/examples/ScpFrom.java.html
我会尝试将代码存放在那里,然后修改它以逐行读取远程文件而不是写入本地文件,但是一旦作者声明了一个字节数组并开始从中读取字节,大部分代码都是希腊语.远程文件.我承认这是我几乎不了解的事情; BufferedReader提供了更高级别的接口.基本上我想这样做:如何使用Java逐行读取大型文本文件?
除了使用BufferReader,它还可以逐行读取远程文件,如果提供了主机名和用户凭据(密码等),即RemoteBufferReader?
这是我写的测试代码; 如何使用JSCh逐行读取远程文件?
public class test2
{
static String user = "myusername";
static String host = "user@remotehost";
static String password = "mypasswd";
static String rfile = "/path/to/remote/file/on/remote/host";
public static void main(String[] args) throws FileNotFoundException, IOException, JSchException
{
JSch jsch=new JSch();
Session session=jsch.getSession(user, host, 22);
session.setPassword(password);
session.connect();
// exec 'scp -f rfile' remotely
String command="scp -f "+rfile;
Channel channel=session.openChannel("exec");
((ChannelExec)channel).setCommand(command);
// get I/O streams for remote scp
OutputStream out=channel.getOutputStream();
channel.connect()
//no …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用JSCH将文件上传到远程SFTP共享.每次我尝试从我的代码中连接到共享时,我都会得到一个看起来像这样的异常:
com.jcraft.jsch.JSchException: Session.connect: java.security.InvalidKeyException: Key is too long for this algorithm
at com.jcraft.jsch.Session.connect(Session.java:558) ~[jsch-0.1.51.jar:na]
at com.jcraft.jsch.Session.connect(Session.java:183) ~[jsch-0.1.51.jar:na]
Run Code Online (Sandbox Code Playgroud)
我在升级到Java 8时看过描述此错误的帖子,但我们仍然使用Java 7,而且我对Java的加密支持知之甚少,不知道这是否重要.
有些人建议安装JCE(Java Cryptography Extensions)来解决这个问题,所以我试了一下,但是在将相应的jar文件复制到/ libs/security目录并重新启动应用程序之后,我仍然会遇到同样的错误.我们确认通过执行此脚本安装了JCE,并注意到没有抛出异常.
我还尝试使用sftp详细模式下的命令从终端连接到远程SFTP共享.这是我得到的:
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: /etc/ssh_config line 102: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to XXXXXXXXXXXXX [XXXXXXXXXXXX] port XX.
debug1: Connection established.
debug3: Incorrect RSA1 identifier …Run Code Online (Sandbox Code Playgroud) 当使用jsch版本0.1.51连接到远程主机时,我们在调用Channel.connect()a 时偶尔会遇到以下异常ChannelExec.
com.jcraft.jsch.JSchException: channel is not opened.
at com.jcraft.jsch.Channel.sendChannelOpen(Channel.java:765)
at com.jcraft.jsch.Channel.connect(Channel.java:151)
at com.jcraft.jsch.Channel.connect(Channel.java:145)
Run Code Online (Sandbox Code Playgroud)
我们在创建会话后使用的代码是:
ChannelExec channel = (ChannelExec) session.openChannel("exec");
channel.setCommand("echo hello");
channel.connect(); // Error here
Run Code Online (Sandbox Code Playgroud)
该Channel.connect()调用通常在100毫秒内返回,但是当出现此错误时,调用会在抛出异常之前挂起超过20秒.
如何在使用JSCH SFTP API创建新目录之前检查目录是否存在?我正在尝试使用,lstat但不确定它是否正在完成我需要的工作.谢谢你提前