forked from striner/javaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFTPUtilTest.java
More file actions
51 lines (41 loc) · 1.65 KB
/
Copy pathFTPUtilTest.java
File metadata and controls
51 lines (41 loc) · 1.65 KB
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
42
43
44
45
46
47
48
49
50
51
package utils;
import common.utils.FTPUtil;
import org.apache.commons.net.ftp.FTPFile;
import org.junit.Test;
import java.io.*;
import java.util.List;
import java.io.IOException;
public class FTPUtilTest {
@Test
public void test() throws Exception {
FTPUtil ftpUtil = new FTPUtil("UTF-8");
ftpUtil.connect("192.168.1.198", 21, "striner", "murong123456");
ftpUtil.upload("/home/striner/test1.txt", new File("E:/striner/test1.txt"));
ftpUtil.download("/home/striner/test1.txt", new File("E:/striner/test11.txt"));
ftpUtil.uploadDir("/home/striner/ccc", "E:/striner");
ftpUtil.downloadDir("/home/striner/ccc", "E:/striner/aaa");
ftpUtil.disconnect();
}
@Test
public void test2() throws IOException{
FTPUtil ftpUtil = new FTPUtil("UTF-8");
ftpUtil.connect("192.168.1.198", 21, "striner", "murong123456");
List<FTPFile> files = ftpUtil.listFiles("/home/striner");
for (FTPFile file : files) {
System.out.println(file.getName());
}
ftpUtil.disconnect();
}
@Test
public void test3() throws IOException {
FTPUtil ftpUtil = new FTPUtil("UTF-8");
ftpUtil.connect("192.168.1.198", 21, "striner", "murong123456");
ByteArrayInputStream in = new ByteArrayInputStream("FTP测试".getBytes());
ftpUtil.storeFile("/home/striner/xyz.txt", in);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ftpUtil.retrieveFile("/home/striner/xyz.txt", bos);
String contentStr = new String(bos.toByteArray(),"utf8");
System.out.println(contentStr);
ftpUtil.disconnect();
}
}