jschDemo
jsch是java的sftp实现
import com.jcraft.jsch.*;
import java.io.OutputStream;
public class JschStart {
public static void main(String[] args) throws Exception {
JSch jSch = new JSch();
Session session = jSch.getSession("user1","30.4.101.45");
session.setPassword("hello123");
session.setConfig("StrictHostKeyChecking", "no");
session.setTimeout(60000);
session.connect();
Channel channel = session.openChannel("sftp");
if (channel == null){
System.out.println("空");
} else {
System.out.println("非空");
}
channel.connect();
ChannelSftp channelSftp = (ChannelSftp) channel;
channelSftp.cd("tmp1");
OutputStream outputStream = channelSftp.put("test.txt");
outputStream.write("110".getBytes());
outputStream.flush();
outputStream.close();
session.disconnect();
((ChannelSftp) channel).quit();
channel.disconnect();
System.out.println("程序结束");
System.err.println("程序结束");
}
}
jschDemo的更多相关文章
随机推荐
- huffman(greedy)
present a file by binary character code,let the less characters can be presented simplier. package g ...
- laravel 解决保存Emoji 表情问题
ALTER DATABASE database_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci; ALTER TABLE table ...
- 自动化测试-14.selenium加载FireFox配置
前言 有小伙伴在用脚本启动浏览器时候发现原来下载的插件不见了,无法用firebug在打开的页面上继续定位页面元素,调试起来不方便 . 加载浏览器配置,需要用FirefoxProfile(profile ...
- mysql locking
1. 意向锁 https://dev.mysql.com/doc/refman/5.7/en/innodb-locking.html#innodb-insert-intention-locks 官方文 ...
- CC3000 Arduino 连接Yeelink中文注释 示例
代码如下“ /*************************************************** *这是一个例子的dfrobot维多-无线集成物联网建兴传感器和控制节点 *产品页面 ...
- list基本代码
#include<iostream> #include<list> //STL之list的基本用法 using namespace std; void outputList(l ...
- POJ2376 Cleaning Shifts
题意 POJ2376 Cleaning Shifts 0x50「动态规划」例题 http://bailian.openjudge.cn/practice/2376 总时间限制: 1000ms 内存限制 ...
- C# 以共享只读方式打开被其它程序占用的文件
iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read, Sys ...
- 面試題之web
1. django和flask框架的区别? django:大而全的全的框架,重武器:内置很多组件:ORM.admin.Form.ModelForm.中间件.信号.缓存.csrf等 flask: 微型框 ...
- ILBC 运行时 (ILBC Runtime) 架构
本文是 VMBC / D# 项目 的 系列文章, 有关 VMBC / D# , 见 <我发起并创立了一个 VMBC 的 子项目 D#>(以下简称 <D#>) https:// ...