jsch

Getting session and SFTP channel in Java using JSch library

时间秒杀一切 提交于 2019-12-06 12:02:49
I am using JSch library for SFTP. I need to do several operations on SFTP server like move remote files in other directory, pull files, etc. For all these operations I need Session and from it I get Channel an then cast it to ChannelSftp . This is redundant step. So I thought of abstracting it into a private method. private ChannelSftp getChannelSftp() throws JSchException { java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); JSch jsch = new JSch(); Session session; session = jsch.getSession(VENDOR1_USERID, VENDOR1_SERVER, VENDOR1_PORT); session

JSch ChannelSftp.ls - pass match patterns in java

江枫思渺然 提交于 2019-12-06 11:46:23
问题 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 ? 回答1: ChannelSftp.ls takes as argument a path: http://epaul.github

How to reput on JSch SFTP?

会有一股神秘感。 提交于 2019-12-06 09:30:24
I'm using JSch to upload files to a SFTP. It works but sometimes the TCP connection is shut down while a file is being uploaded resulting on a truncated file on the server. I found out that the reput command on SFTP servers resumes the upload. How can I send a reput command with JSch? Is it even possible? Here's my code: public void upload(File file) throws Exception { JSch jsch = new JSch(); Session session = jsch.getSession(USER, HOST, PORT); session.setPassword(PASSWORD); java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); session.setConfig

Transfer string content to a file in remote machine using java

只谈情不闲聊 提交于 2019-12-06 08:05:54
I need to place a string content in a remote file. Ideally, I used to create a file in local and then transfer that file to remote machine. Below is the code snippet I used, to copy file to remote. ChannelSftp sftpChannel = (ChannelSftp) channel; File file = new File(filePathWithName);//To read the file in local machine try { sftpChannel.cd(location);//Remote location //Transferring the file to RemoteLocation. sftpChannel.put(new FileInputStream(file), file.getName());//.(Here I don't want read a file.) //Instead I want copy a content which is in string variable, something like below two lines

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

青春壹個敷衍的年華 提交于 2019-12-06 06:00:55
问题 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

com.jcraft.jsch.ChannelSftp.throwStatusError

蹲街弑〆低调 提交于 2019-12-06 06:00:52
Am trying to create a folder(folderName) and two files(file1.txt,file2.txt) in it.After creating folder and files, am updating its permissions.First update files' permissions then folder's.But when folder permission is getting called for update, exception is thrown.Even exception is thrown permission of the folder and files are updated properly.Please help me to find how I can prevent this Exception. Update1 : channelSftp.chmod(511, folder); //commenting this line, works without exception but can't update permission of folder. Update2 : channelSftp.chmod(511, folder); //this line is the

Executing a command using JSch

百般思念 提交于 2019-12-06 05:04:05
I'm using JSch to automate remotely launching a python script from a background Java process. Modifying the Shell.java example included in the JSch package, I've successfully installed JSch, connected to my Pi, and even commented out the user/domain/password/host key checking prompt boxes in favor of storing these values directly in my Java code. After my java code logs into the remote Pi, I'd like it to send something like sudo nohup python2 myFoo.py & disown to the terminal. In the Shell.java example I'm modifying, I see lines of code redirecting the input and output streams of the channel

com.jcraft.jsch.JSchException: java.net.ConnectException: Connection refused: connect

你离开我真会死。 提交于 2019-12-06 05:00:05
I understand that there is duplicate >>> copied from the duplicate >>>As long as your local machine has an SSH server running <<<<< but i cannot comment and cannot as from the question (and im not providing an answer....) It stated that "As long as your local machine has an SSH server running" but I do not know how to have a SSh server running. I turn on my putty (double click on it) (not sure if this means the SSH(?Putty?) server (?) is running... doubt so... im really new to socket programming. i am making use of JSch ( http://www.jcraft.com/jsch/ ) to try to connect to a remote server

Configuring known_hosts in jgit

两盒软妹~` 提交于 2019-12-06 01:37:29
问题 Using jgit with gitolite for source control, I have an application that generates certain code on command and which we want to be committed to source control. The goal is to pull with a fast forward, commit the new code, and then push it. I have the following method: private void commitToGitRepository(String updateComment, Config config) throws IOException, NoFilepatternException, GitAPIException { if(git == null) { git = Git.open(new File(config.getDpuCheckoutDir())); } PullCommand pull =

Gerrit replicating to gitolite fails

两盒软妹~` 提交于 2019-12-06 01:32:30
I have configured the replication with following configurations $cat /var/gerrit/review_site/etc/replication.config [gerrit] autoReload=true [remote "bt-git"] projects = ^vt-(.*)$ push = refs/heads/*:refs/heads/* url = git@git.something.com:/${name}.git My ssh config file looks like this one, Host git HostName git.something.com User git IdentityFile /var/gerrit/.ssh/id_rsa StrictHostKeyChecking no UserKnownHostsFile /dev/null Although I have already added the right set of hostkeys in my ~/.ssh/known_hosts the replication plugin fails with the following stacktrace [2017-08-02 13:08:55,194]