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("程序结束"); } }