提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.infra.framework.file.core.sftp; |
H |
2 |
|
|
3 |
import cn.hutool.core.io.resource.ResourceUtil; |
|
4 |
import cn.hutool.core.util.IdUtil; |
|
5 |
import com.iailab.module.infra.framework.file.core.client.sftp.SftpFileClient; |
|
6 |
import com.iailab.module.infra.framework.file.core.client.sftp.SftpFileClientConfig; |
|
7 |
import org.junit.jupiter.api.Disabled; |
|
8 |
import org.junit.jupiter.api.Test; |
|
9 |
|
|
10 |
public class SftpFileClientTest { |
|
11 |
|
|
12 |
@Test |
|
13 |
@Disabled |
|
14 |
public void test() { |
|
15 |
// 创建客户端 |
|
16 |
SftpFileClientConfig config = new SftpFileClientConfig(); |
|
17 |
config.setDomain("http://127.0.0.1:48080"); |
|
18 |
config.setBasePath("/home/ftp"); |
|
19 |
config.setHost("kanchai.club"); |
|
20 |
config.setPort(222); |
|
21 |
config.setUsername(""); |
|
22 |
config.setPassword(""); |
|
23 |
SftpFileClient client = new SftpFileClient(0L, config); |
|
24 |
client.init(); |
|
25 |
// 上传文件 |
|
26 |
String path = IdUtil.fastSimpleUUID() + ".jpg"; |
|
27 |
byte[] content = ResourceUtil.readBytes("file/erweima.jpg"); |
|
28 |
String fullPath = client.upload(content, path, "image/jpeg"); |
|
29 |
System.out.println("访问地址:" + fullPath); |
|
30 |
if (false) { |
|
31 |
byte[] bytes = client.getContent(path); |
|
32 |
System.out.println("文件内容:" + bytes); |
|
33 |
} |
|
34 |
if (false) { |
|
35 |
client.delete(path); |
|
36 |
} |
|
37 |
} |
|
38 |
|
|
39 |
} |