jsch

JSch get() fails with NullPointerException

这一生的挚爱 提交于 2019-12-04 20:06:12
I've got a Jax-RS server which is supposed to keep a list of files accessible via ssh that I can then download or stream via HTTP. I've been trying to read the files with JSch's SFTP channel, but I keep receiving a NullPointerException . Here's the MessageBodyWriter I wrote: @Provider @Produces("video/*") public class MediaBodyWriter implements MessageBodyWriter<MediaFile> { @Override public long getSize(MediaFile mFile, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) { return mFile.getFileSize(); } @Override public boolean isWriteable(Class<?> type, Type arg1, Annotation[] arg2,

JSch/SSHJ - Connecting to SSH server on button click

冷暖自知 提交于 2019-12-04 19:22:18
I'm trying to connect to SSH Unix server on button click (code written in actionPerformed() method). I'm using JSch for connecting to SSH server. The code is written in SwingWorker class as it is a network operation. private void testConnectionButtonActionPerformed(java.awt.event.ActionEvent evt) { SwingWorker<Boolean, Void> sw = new SwingWorker<Boolean, Void>(){ @Override protected Boolean doInBackground() throws Exception { JSch jsch = new JSch(); String host = "ServerHost"; String username = "username"; String password = "password"; Session session = jsch.getSession(username, host); session

Basic SSH connection via JSCH on android

大兔子大兔子 提交于 2019-12-04 19:14:45
As the fellow user from this question and this tutorial explain, I'm trying to setup a simples ssh connection to perform a single command on a app. It dosen't even need to wait for any response. Here is the code: Main Activity: package com.example.lucas.shutdown; import android.os.AsyncTask; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import com.jcraft.jsch.Channel; import com.jcraft.jsch.ChannelExec; import com.jcraft.jsch.JSch; import com.jcraft.jsch.Session; public class MainActivity extends AppCompatActivity { @Override protected

Run remote commands through SSH tunnel in Java

余生颓废 提交于 2019-12-04 18:55:55
I need to run some commands from a remote computer using an SSH connection, but the problem is the following: The client computer (running Windows) is connected to a network where I can see a server remote (second *nix computer, in the same network). I can do SSH connections with it, however the computer that contains the files (running *nix) isn't in this network, I only can connect with this trough a dynamic SSH tunnel open in the second computer, where I normally use PuTTY to configure this connection. Then I've got access to the remote files. The following picture represents the

JSch ChannelSftp.ls - pass match patterns in java

╄→尐↘猪︶ㄣ 提交于 2019-12-04 18:08:46
I have multiple files at an sftp location like xyz_20140101.csv.gz xyz_2014_01_01.csv.gz xyz_20140202.csv.gz xyz_2014_02_02.csv.gz through my java program i want to get list of files only in format xyz_YYYYMMDD.csv.gz , what should be my match pattern to pass in ChannelSftp.ls command . I am passing pattern = xyz_*csv.gz , but it gives me all the files . ChannelSftp.ls(pattern); What should be my pattern to pass in ls command ? ChannelSftp.ls takes as argument a path: http://epaul.github.io/jsch-documentation/javadoc/com/jcraft/jsch/ChannelSftp.html#ls(java.lang.String) the path can contain

java实现ssh登录linux服务器并下发命令

雨燕双飞 提交于 2019-12-04 13:39:04
依赖jar包:jsch-0.1.55.jar commons-io-2.5.jar import com.jcraft.jsch.ChannelExec; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; import org.apache.commons.io.IOUtils; import java.io.*; public class SSHTest { public static void main(String[] args) throws JSchException, IOException { //建立连接 int port=22; String host="10.XX.XX.XX"; String userName="admin"; String password="XXXX"; JSch jsch = new JSch(); Session session = jsch.getSession(userName, host, port); session.setPassword(password); session.setConfig("StrictHostKeyChecking","no"); session

How to run and display the result of a shell command ssh with JSch?

雨燕双飞 提交于 2019-12-04 13:16:07
问题 I try to use the library JSch - Java Secure Channel make an ssh connection in my Android app, it works. Now I would like to execute a command and retrieve the result. I tried several methods that works best is this. However, this method works only in part, because for some reason I can not explain, my program stops at the end of my while loop, yet I'm the result of the command that appears in my log. Here is my code : public static String executeRemoteCommand(String username, String password,

SFTP Read all files in directory

孤人 提交于 2019-12-04 11:46:54
I have created a successful connection using SFTP com.jcraft.jsch I also created a directory folder under HostDir like: channelSftp.mkdir("sftp.test"); Now i want to read all file/folder names under host directory, I do not see any appropriate method or example. thanks Done it using this .. ChannelSftp sftp = (ChannelSftp) channel; sftp.cd(hostDir); Vector<String> files = sftp.ls("*"); for (int i = 0; i < files.size(); i++) { Object obj = files.elementAt(i); if (obj instanceof com.jcraft.jsch.ChannelSftp.LsEntry) { LsEntry entry = (LsEntry) obj; if (true && !entry.getAttrs().isDir()) { ret.add

Cannot connect to SFP sever using key file with JSch and Java 8

孤街醉人 提交于 2019-12-04 10:53:33
I am trying to connect to a SFTP server using a 2048 bit RSA key file. It works fine running against version 7r45 of the JRE using JSch but i get the follow exception when running against version 8r31 of the JRE. com.jcraft.jsch.JSchException: Session.connect: java.security.InvalidAlgorithmParameterException: Prime size must be multiple of 64, and can only range from 512 to 2048 (inclusive). It's not an issue with limited Java security policy as I have tried it with and without the unlimited strength jars for both versions of java. I have seen other references to this exception suggesting

How do you set the configuration for jschconfigsessionfactory for jgit so that pull and push work?

蹲街弑〆低调 提交于 2019-12-04 09:25:31
问题 I am trying to do a git pull/push using jgit's api with the following code org.eclipse.jgit.api.Git.open(theRepoFile).pull().call() but I am getting exceptions 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