操作远程计算机文件
2015-07-01 17:06
525 查看
public static void main(String[] args) { SshClient client=new SshClient(); try{ client.connect("ip"); PasswordAuthenticationClient pwd = new PasswordAuthenticationClient(); pwd.setUsername("user"); pwd.setPassword("password"); int result=client.authenticate(pwd); if(result==AuthenticationProtocolState.COMPLETE){ List<SftpFile> list = client.openSftpClient().ls("/test/folder"); //client.openSftpClient().mkdir("/test/folder/test"); for (SftpFile f : list) { System.out.println(f.getFilename()); System.out.println(f.getAbsolutePath()); /* if(f.getFilename().equals("aliases")){ OutputStream os = new FileOutputStream("d:/mail/"+f.getFilename()); client.openSftpClient().get("/etc/mail/aliases", os); File file = new File("d:/mail/aliases"); BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(file)); String tempString = null; int line = 1; while ((tempString = reader.readLine()) != null) { System.out.println("line " + line + ": " + tempString); line++; } reader.close(); } catch (IOException e) { e.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e1) { } } } }*/ } } }catch(IOException e){ e.printStackTrace(); } }
但是没有找到能新建文件的方法。。
需要jar:j2ssh-core-0.2.2.jar
相关文章推荐
- iOS开发——post异步网络请求封装
- 初识Volley的基本用法
- UNIX网络进程间通信漫谈(1)
- 【Linux 内核网络协议栈源码剖析】bind 函数剖析
- 【数据结构】排序
- 【数据结构】查找
- 多台计算机安装ssh
- 重构网络库
- JAVA代码java.net.URLConnection发送HTTP请求的方法
- Android-监听网络状态
- TCP字节流与UDP数据报
- tcp/ip ,http,socket 区别
- HttpPost目的就是加载时第2次,第3次,第n次执行的方法 还有一个就是[httpGet] 是第一次加载的时候指定调用的
- linux网络:常用命令(二)
- 两种双链表操作
- 数据结构习题之多维数组和广义表
- 网络-数据序列化之protobuf
- iOS9 new_001:iOS9网络适配(ATS)
- android 网络编程之网络通信几种方式实例分享
- Iphone设置http代理使用Fiddle抓包