jsch

远程执行 Linux/UNIX 系统上任务的框架 -- sshxcute

时间秒杀一切 提交于 2019-12-10 16:28:03
软件开发与测试人员常常会在远程 Linux/UNIX 系统上执行命令或脚本,有时还会有批量执行任务的需求。常见的办法是通过本地工具(例如 Putty)连接远程计算机,输入命令执行,但是当遇到需要集成这些任务到代码或者开发、测试框架中时,往往就没有很好的解决方案了。sshxcute 就是这样一个框架工具集,它基于 JSCH 构建,允许工程师利用 Java 代码通过 SSH 连接远程批量执行 Linux/UNIX 系统上的命令或者脚本,同时加入了判断成功与否,取回输出等多种实用功能。sshxcute 不管是针对软件开发、测试还是系统部署,都简化了自动化流程与系统环境部署的步骤。 http://www.ibm.com/developerworks/cn/opensource/os-sshxcute/ 来源: oschina 链接: https://my.oschina.net/u/129540/blog/14781

To run sudo commands on a ec2 instance

只谈情不闲聊 提交于 2019-12-10 14:50:09
问题 I cannot run "sudo su" on my ec2 client , I ssh into the client through a java program and run the command through a program. I can run commands like "ls" and "ifconfig" though. I get an error saying "sudo: sorry, you must have a tty to run sudo". How can I run the command, I am using Jsch for ssh to my ec2 instance. 回答1: You can do "sudo" without pseudo-tty with JSch, by using the -S option to sudo . See the Sudo.java on the JSch website for a complete example. (I'm the author of JSch.) 回答2:

JSchException timeout: socket is not established

北战南征 提交于 2019-12-10 13:48:22
问题 I am trying to use JSch to connect to my computer through ssh and then run a command. However, when I run the code I never connect to the computer. and the following error: I/System.out: com.jcraft.jsch.JSchException: timeout: socket is not established Here is my relevant code: protected void sshTesting(){ String name = ""; String userName = "kalenpw"; String password = "hunter2"; String ip = "192.168.0.4"; int port = 22; String command = "cmus-remote -u"; try{ JSch jsch = new JSch(); Session

JSch

只谈情不闲聊 提交于 2019-12-10 13:30:38
JSch是Java Secure Channel的缩写。JSch是一个SSH2的纯Java实现。它允许你连接到一个SSH服务器,并且可以使用端口转发,X11转发,文件传输等,当然你也可以集成它的功能到你自己的应用程序。 本文只介绍如何使用JSch实现的SFTP功能。 SFTP是Secure File Transfer Protocol的缩写,安全文件传送协议。可以为传输文件提供一种安全的加密方法。SFTP 为 SSH的一部份,是一种传输文件到服务器的安全方式。SFTP是使用加密传输认证信息和传输的数据,所以,使用SFTP是非常安全的。但是,由于这种传输方式使用了加密/解密技术,所以传输效率比普通的FTP要低得多,如果您对网络安全性要求更高时,可以使用SFTP代替FTP。(来自百度的解释) 要使用JSch,需要下载它的jar包,请从官网下载它: http://www.jcraft.com/jsch/ ChannelSftp类是JSch实现SFTP核心类,它包含了所有SFTP的方法,如: put(): 文件上传 get(): 文件下载 cd(): 进入指定目录 ls(): 得到指定目录下的文件列表 rename(): 重命名指定文件或目录 rm(): 删除指定文件 mkdir(): 创建目录 rmdir(): 删除目录 等等(这里省略了方法的参数,put和get都有多个重载方法

SFTP ChannelSftp.put stop it's execution process but successfully being uploaded or copy the source file

人盡茶涼 提交于 2019-12-10 12:25:02
问题 details: in my API i have struggle on debugging why is that the ChannelSftp.put method hangs up or stop it's execution process but when checking it's output it is successfully being uploaded. here's my code snippet: MyService.class @Inject MyConfiguration conf; public String copyAndMove( String fileName ){ try{ MyServer origin = conf.getOriginServer().setFileName( fileName ); MyServer destination = conf.getDestinationServer().setFileName( fileName ); SFTPServer originSftpServer = new

How to upload from Android using jsch sftp?

时间秒杀一切 提交于 2019-12-10 12:23:17
问题 I'm trying to upload a picture from Android phone's DCIM folder using JSCH SFTP. This is the main part of the code: channelSftp2.put("/storage/emulated/0/DCIM/Camera/IMG_20180118_122224.jpg","/home/pi/IMG_20180118_122224.jpg"); But unfortunately it doesn't work. The logcat does not give any specific errors. I changed /storage/emulated/0/DCIM/Camera/IMG_20180118_122224.jpg to /sdcard/DCIM/Camera/IMG_20180118_122224.jpg but nothing changed. I'm writing the codes in Android Studio 2.2.2 and the

Need to combine “Sudo” and “ScpTo” examples of JSch

℡╲_俬逩灬. 提交于 2019-12-10 12:16:02
问题 I'm unsuccessful with combining "Sudo" and "ScpTo" cases. I noticed, that both work through "exec" channel. Clean "ScpTo" case finishes with "Permission denied" message. "Sudo" case Channel channel = session.openChannel("exec"); ((ChannelExec) channel).setCommand("sudo -S -u <supervisor> whoami"); works fine. When I connect to my server through FarManager I write server option: sudo su -l <supervisor> -c /usr/libexec/openssh/sftp-server Also, I can run usual SFTP client like this: sftp -s

Displaying Midnight Commander screen in JTextPane

試著忘記壹切 提交于 2019-12-10 12:14:16
问题 I've tried to connect by SSH to a server and get an output for my commands. Everything works fine if I put out into System.out . Else if I want to put it into JTextPane , it puts it, but MC is unreadable. This is my code: JSch jsch = new JSch(); String command = ""; String commandR = ""; host = null; if (arg.length > 1) { host = arg[0]; command = arg[2]; commandR = arg[3]; } String user = host.substring(0, host.indexOf('@')); host = host.substring(host.indexOf('@') + 1); Session session =

JSch - Explaining SCP stream reading [closed]

ⅰ亾dé卋堺 提交于 2019-12-10 12:09:11
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . I'm having hard times trying to understand example codes from JSch library. For example say, that I want to understand this code (example of scpFrom). I can't understand how that buffer, declared on line 56, works. How can that buffer contain for example read,write,execute flags, file size and first 7 chars of

Why do I see scrabbled output when using JSch?

跟風遠走 提交于 2019-12-10 11:58:34
问题 I am trying to use JSch . I tried the example here Although I can connect the output is weird. I get the following: Last login: Thu Jan 31 19:44:25 2013 from 10.2.251.77 [1mcli:~ # [m And if I do e.g. an ls I get: [0m[01;34m.InstallAnywhere[0m [00m.bash_history [00m.bash_profile[0m [01;34mbin[0m [00msles11-patched[0m [01;34m.kbd[0m [00mindex.html[0m [00mtest.sql[0m [00m.viminfo[0m [00;31mipvsadm-1.26-1.src.rpm[0m [m[1mcli:~ # [m These are the directory contents but why are they displayed like