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