jsch

Multiple commands using JSch

ⅰ亾dé卋堺 提交于 2020-01-09 05:29:16
问题 My requirement is as follow: I have to login to Unix box using my credentials and once login, I have to do sudo to different user. Once sudo is successful, I have to invoke shell in nohup. On completion of executions, close channel and session both. I tried the first step which is connect using sudo command, but I don't know how to invoke shell script after the sudo command. In the below code I am able to execute sudo command, but after getting sudo access how can I execute a shell in nohup

How to pass the input value to shell script using java

久未见 提交于 2020-01-07 07:52:11
问题 I have created the shell script to add two numbers. I want to execute that shell script from java and I am using Jsch library. Can you please help me on this. first_num=0 second_num=0 echo -n "Enter the first number-->" read first_num echo -n "Enter the second number-->" read second_num echo "first number + second number = $ (( first_num + second_num ))" Yes. I have checked examples in "Jsch" sites, But i am not able to enter the input to shell script. I tried as you said. Please see the

Java File commands over SSH

我们两清 提交于 2020-01-07 06:17:10
问题 I'm creating a java program which does a lot over ssh. In my program, I need to be able to run methods such as "listFiles()" on a remote host. I also need to be able to run a couple commands from Apache Commons io (I'm using the "FileUtils" class). I've seen programs such as JSch, but none of them have enough flexibility when it comes to file manipulation and transfer. Could anyone suggest an alternate program or approach to my problem? 回答1: On the contrary, JSch does support file transfer:

Java File commands over SSH

a 夏天 提交于 2020-01-07 06:15:12
问题 I'm creating a java program which does a lot over ssh. In my program, I need to be able to run methods such as "listFiles()" on a remote host. I also need to be able to run a couple commands from Apache Commons io (I'm using the "FileUtils" class). I've seen programs such as JSch, but none of them have enough flexibility when it comes to file manipulation and transfer. Could anyone suggest an alternate program or approach to my problem? 回答1: On the contrary, JSch does support file transfer:

Display remote directory/all files in Jtree

我只是一个虾纸丫 提交于 2020-01-07 02:44:30
问题 i have some problem using JSCH to retrieve files/folders and populate them in JTree. In JSCH to list files using : Vector list = channelSftp.ls(path); But i need that lists as java.io.File type. So i can get absolutePath and fileName, And i don't know how to retrieve as java.io.File type. Here is my code, and i try it work for local directory. public void renderTreeData(String directory, DefaultMutableTreeNode parent, Boolean recursive) { File [] children = new File(directory).listFiles(); //

how to set chmod permission in java jsch channelsftp setPermission(int permission, String path)

流过昼夜 提交于 2020-01-05 03:33:32
问题 How can I convert a chmod value like 755 so it fits in channelSftp setPermission(int permission, String path)? I can't figure it out. :( EDIT: Here it says I'm suppose to use a bitmask. But I'm not sure how that would be done either. http://epaul.github.com/jsch-documentation/javadoc/com/jcraft/jsch/SftpATTRS.html#setPERMISSIONS(int) 回答1: Permission perm = new Permission(); //set the permissions you want. setPermission(perm.getDecimalCode(), path); You can get the Permission class from here:

Change file permissions with SFTP or SCP uing JSch

↘锁芯ラ 提交于 2020-01-04 05:30:45
问题 I have a user account, but on trying using this am getting exception for rssh. Is there any possibility to give permission of directory using other way other than ChannelExec . Based on the exception I come to know this account can't use ChannelExec to give permission of a directory or file. Thus is there any other way this account could give file permission without getting access to this user account for rssh . Please give you thoughts. Code : channelSftp = (ChannelSftp) channel; ChannelExec

Ant scp task: JSchException: invalid privatekey [duplicate]

徘徊边缘 提交于 2020-01-03 07:03:05
问题 This question already has answers here : “Invalid privatekey” when using JSch (3 answers) Closed 10 months ago . I created a new key pair using ssh-keygen and added the public key on the server. Using sftp -i private_key_file user@server I can successfully open a connection to the server and put files. However, when I try to use the Ant scp task I receive: com.jcraft.jsch.JSchException: invalid privatekey: [B@5e9d5728 The relevant part of the Ant script: <scp file="local-file.zip" trust="true

Signature length not correct: got 127 but was expecting 128

耗尽温柔 提交于 2020-01-01 09:16:21
问题 I am facing a strange problem after java 1.8 upgrade. I am using jsch-0.1.54.jar in one of our utility programs to download files from various places. This particular utility was being used for almost 4-5 years without any problem(back then it jsch-0.1.48). At that time environment was java 1.6. Recently we upgraded to java 1.8 and as a result we upgraded this particular utility. Now we are encountering a strange problem and it occurs occasionally, and most of the time the download of files

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

巧了我就是萌 提交于 2020-01-01 09:05:47
问题 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