jsch

How to use Java JSch library to read remote file line by line?

為{幸葍}努か 提交于 2020-01-01 09:05:07
问题 I am trying to use Java to read a file line by line, which is very simple (there are multiple solutions for this on stackoverflow.com), but the caveat here is that the file is located on a remote server, and it is not possible to get a local copy (it is a massive collection of millions of Amazon reviews in a single .txt file). JSch comes with two example classes that copy files to and from remote hosts, namely ScpTo and ScpFrom. I am interested in reading the file from the remote host line by

Using JSch ChannelSftp: How to read multiple files with dynamic names?

风格不统一 提交于 2019-12-31 09:00:13
问题 I have to read a bunch of .CSV files with dynamic file names from a SFTP server. These files get generated every 15 minutes. I am using JSch's ChannelSftp, but there is no method which would give the exact filenames. I only see an .ls() method. This gives a Vector e.g. [drwxr-xr-x 2 2019 2019 144 Aug 9 22:29 ., drwx------ 6 2019 2019 176 Aug 27 2009 .., -rw-r--r-- 1 2019 2019 121 Aug 9 21:03 data_task1_2011_TEST.csv, -rw-r--r-- 1 2019 2019 121 Aug 9 20:57 data_task1_20110809210007.csv] Is

Java JSch create channel to access remote server via HTTP(s)

跟風遠走 提交于 2019-12-31 07:32:32
问题 Using the code at http://www.jcraft.com/jsch/examples/StreamForwarding.java.html, I have tried to create code that uses JSch to connect to an SSH server, then use it to connect to a server in the Web and pass HTTP(s) requests to the server, basically using the SSH server as a proxy. Here is what I have: //SSH server and credentials String host = "00.000.000.00"; String user = "login"; String password = "password"; int port = 22; //The host I want to send HTTP requests to - the remote host

OpenSSH8.0对应jsch jar包版本

一世执手 提交于 2019-12-30 14:06:31
由于连接sftp所用jar最终会使用jsch的包。然而jsch的包会有各种版本问题。来梳理一下, 根源是jdk1.6支持的加密算法较少(jdk8支持了大多数加密算法),而openSSH8.0默认屏蔽了jdk1.6支持的加密算法,如:diffie-hellman-group1-sha1等。openSSH7的版本能支持1.6的算法。 首先查看主机ssh命令,执行ssh -v 因为一台主机可能放多个项目,那么不能换全局的jdk。每个项目可以指定jdk启动,在tomcat的bin目录下setclasspath.sh,和catalina.sh中增加 export JAVA_HOME=/ecp_web/jdk1.8/jdk1.8.0_171(jdk路径) export JRE_HOME=/ecp_web/jdk1.8/jdk1.8.0_171/jre(jre路径) jdk1.6+OpenSSH8.0+jsch1.0.50.jar(不行,最原始版本) OpenSSH8.0对应的jsch包应该在52版本或者更高 jdk1.6+OpenSSH8.0+jsch1.0.52.jar(有解决方案。网上说法,未亲测) 修改/etc/ssh/sshd_config文件,增加sshd的算法配置。 KexAlgorithms +diffie-hellman-group1-sha1 jdk1.6+OpenSSH8

Jsch and sudo command

安稳与你 提交于 2019-12-30 13:52:06
问题 I am trying to automate some operations and one of such an operation is switching to a technical user on a remote Linux machine. The procedure looks like this: log in with a "normal" user and then switch with sudo /bin/rootsh -i -u techUser to the technical user. Here's my Groovy code example that I am working on: import com.jcraft.jsch.JSch import com.jcraft.jsch.Session import com.jcraft.jsch.Channel import com.jcraft.jsch.ChannelExec import com.jcraft.jsch.JSchException class Main { static

How do I copy files stored in a remote SFTP server to another folder in the same remote server using Java?

筅森魡賤 提交于 2019-12-30 11:42:27
问题 I have been trying to copy few selected files (after performing few checks), in a remote server to the same remote server using: File localFile = new File(srcPath); sftpChannel.put(localFile.getAbsolutePath(),localFile.getName()); I have even tried to copy those selected files to my local machine using the get() method. Can somebody help? 回答1: A core SFTP protocol does not support duplicating a remote file. There's draft of copy-file extension to the protocol, but that's supported by only few

How do I copy files stored in a remote SFTP server to another folder in the same remote server using Java?

不羁的心 提交于 2019-12-30 11:42:19
问题 I have been trying to copy few selected files (after performing few checks), in a remote server to the same remote server using: File localFile = new File(srcPath); sftpChannel.put(localFile.getAbsolutePath(),localFile.getName()); I have even tried to copy those selected files to my local machine using the get() method. Can somebody help? 回答1: A core SFTP protocol does not support duplicating a remote file. There's draft of copy-file extension to the protocol, but that's supported by only few

How to move file from directory A to directory B in remote server?

前提是你 提交于 2019-12-30 10:44:14
问题 I am using JSch to connect to SFTP in a website which is made from GWT. I had read a little example of sftpChannel.get() , sftpChannel.rename() , sftpChannel.rm() But I didn't find a solution that copy a file from remote server a directory to remote server b directory. For example, I want to copy file from /appl/user/home/test/temp to /appl/user/home/test/ . Filename = abc.jpg . I stunned here for few hours since most of the solution from network is getting file from remote server to local,

How to set KEX on JSch Session when using Apache VFS

十年热恋 提交于 2019-12-30 09:55:07
问题 I am using Apache VFS 2.1 with JSch 0.1.54 (latest versions today) to upload files using SFTP. The system throws "End of IO Stream Read" when connecting, the complete stack is: Caused by: com.jcraft.jsch.JSchException: Session.connect: java.io.IOException: End of IO Stream Read at com.jcraft.jsch.Session.connect(Session.java:565) at com.jcraft.jsch.Session.connect(Session.java:183) at org.apache.commons.vfs2.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:166) I've

SSH tunneling via JSch

拜拜、爱过 提交于 2019-12-30 04:21:09
问题 My aim is to connect to a server (host) which is behind a firewall. I am able to access this server by connecting to another server (tunnel) in the network and then SSH to this server. However I am not able to implement the same scenario via JSch. I am not able to have the below code work, which I have written for this purpose. Please let me know if I am doing anything silly here. public class JschExecutor { public static void main(String[] args){ JschExecutor t=new JschExecutor(); try{ t.go(