需要导入ganymed-ssh2-build210.jar
import ch.ethz.ssh2.Connection; import ch.ethz.ssh2.SCPClient; import java.io.IOException; /** * Created by Administrator on 2017/6/29. */ public class testScp { public static void main(String[] args){ //创建连接 Connection con = new Connection("132.97.153.51", 22); try { con.connect(); //服务器账号密码 boolean isAuthed = con.authenticateWithPassword("root","123456Qw"); //创建连接 SCPClient scpClient = con.createSCPClient(); //远程获取文件到本地 scpClient.get("/home/testScp0629", "E:/"); } catch (IOException e) { e.printStackTrace(); } } }
本文介绍了一种利用Java中的SCPClient组件实现从远程服务器获取文件的方法。通过使用ganymed-ssh2-build210.jar库,演示了如何建立SSH连接并执行文件传输操作。
1万+

被折叠的 条评论
为什么被折叠?



