mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
基于SSHJ框架SFTP实现
This commit is contained in:
61
hutool-extra/src/test/java/cn/hutool/extra/ftp/SftpTest.java
Normal file
61
hutool-extra/src/test/java/cn/hutool/extra/ftp/SftpTest.java
Normal file
@@ -0,0 +1,61 @@
|
||||
package cn.hutool.extra.ftp;
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.extra.ssh.SshjSftp;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 基于sshj 框架SFTP 封装测试.
|
||||
*
|
||||
* @author youyongkun
|
||||
* @date 2021/12/31 16:11
|
||||
* @since 5.7.18
|
||||
*/
|
||||
public class SftpTest {
|
||||
|
||||
private SshjSftp sshjSftp;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
sshjSftp = new SshjSftp("ip", 22, "test", "test", CharsetUtil.CHARSET_UTF_8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lsTest() {
|
||||
List<String> files = sshjSftp.ls("/");
|
||||
if (files != null && !files.isEmpty()) {
|
||||
files.forEach(System.out::print);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void downloadTest() {
|
||||
sshjSftp.recursiveDownloadFolder("/home/test/temp", new File("C:\\Users\\akwangl\\Downloads\\temp"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uploadTest() {
|
||||
sshjSftp.upload("/home/test/temp/", new File("C:\\Users\\akwangl\\Downloads\\temp\\辽宁_20190718_104324.CIME"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mkDirTest() {
|
||||
boolean flag = sshjSftp.mkdir("/home/test/temp");
|
||||
System.out.println("是否创建成功: " + flag);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mkDirsTest() {
|
||||
// 在当前目录下批量创建目录
|
||||
sshjSftp.mkDirs("/home/test/temp");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delDirTest() {
|
||||
sshjSftp.delDir("/home/test/temp");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user