-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFtpTest.java
81 lines (71 loc) · 2.58 KB
/
FtpTest.java
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package me.saro.test.kit.ee;
import me.saro.kit.ee.ftp.Ftp;
import org.junit.jupiter.api.Test;
import java.io.IOException;
/**
* ftp test
* @see
* org.apache.commons.net.ftp.FTPClient
* com.jcraft.jsch.JSch
*/
public class FtpTest {
@Test
public void test() throws Exception {
// System.out.println("+++++++ FTP +++++++");
// ftp();
//
// System.out.println("+++++++ FTPS (explicit mode) +++++++");
// ftpsExplicitMode();
//
// System.out.println("+++++++ FTPS (implicit mode) +++++++");
// ftpsImplicitMode();
//
// System.out.println("+++++++ S-FTP +++++++");
// sftp();
}
public void ftp() throws IOException {
try (Ftp ftp = Ftp.ftp("test.rebex.net", 21, "demo", "password").open()) {
System.out.println("ftp opened!!");
System.out.println("pwd: " + ftp.pwd());
ftp.listFiles().forEach( it -> System.out.println("file: " + it) );
assert(true);
}
}
public void ftpsExplicitMode() throws IOException {
try (Ftp ftp = Ftp.ftps(false, "test.rebex.net", 21, "demo", "password").open()) {
System.out.println("ftps (explicit mode) opened!!");
System.out.println("pwd: " + ftp.pwd());
ftp.listFiles().forEach( it -> System.out.println("file: " + it) );
assert(true);
}
}
public void ftpsImplicitMode() throws IOException {
try (
Ftp ftp = Ftp
.ftps(true, "test.rebex.net", 990, "demo", "password")
.encoding("UTF-8")
.open()
) {
System.out.println("ftps (implicit mode) opened!!");
System.out.println("pwd: " + ftp.pwd());
ftp.listFiles().forEach( it -> System.out.println("file: " + it) );
assert(true);
}
}
public void sftp() throws IOException {
try (Ftp ftp = Ftp.sftp("test.rebex.net", 22, "demo", "password").open()) {
System.out.println("sftp opened!!");
System.out.println("pwd: " + ftp.pwd());
ftp.listFiles().forEach( it -> System.out.println("file: " + it) );
assert(true);
}
}
public void sftpPublicKey() throws IOException {
try (Ftp ftp = Ftp.sftp("public-key.test.com", 22).userPublicKey("demo", "/user/.ssh/id_rsa").open()) {
System.out.println("sftp opened!!");
System.out.println("pwd: " + ftp.pwd());
ftp.listFiles().forEach( it -> System.out.println("file: " + it) );
assert(true);
}
}
}