1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.commons.net.ftp;
20
21 import java.io.IOException;
22 import java.net.InetAddress;
23 import java.net.ServerSocket;
24 import java.net.Socket;
25 import java.net.UnknownHostException;
26
27 import javax.net.SocketFactory;
28 import javax.net.ssl.SSLContext;
29 import javax.net.ssl.SSLServerSocket;
30
31
32
33
34
35
36
37
38 public class FTPSSocketFactory extends SocketFactory {
39
40 private SSLContext context;
41
42 public FTPSSocketFactory(SSLContext context) {
43 this.context = context;
44 }
45
46 @Override
47 public Socket createSocket(String address, int port) throws UnknownHostException, IOException {
48 return this.context.getSocketFactory().createSocket(address, port);
49 }
50
51 @Override
52 public Socket createSocket(InetAddress address, int port) throws IOException {
53 return this.context.getSocketFactory().createSocket(address, port);
54 }
55
56 @Override
57 public Socket createSocket(String address, int port, InetAddress localAddress, int localPort) throws UnknownHostException, IOException {
58 return this.context.getSocketFactory().createSocket(address, port, localAddress, localPort);
59 }
60
61 @Override
62 public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
63 return this.context.getSocketFactory().createSocket(address, port, localAddress, localPort);
64 }
65
66 public ServerSocket createServerSocket(int port) throws IOException {
67 return this.init(this.context.getServerSocketFactory().createServerSocket(port));
68 }
69
70 public ServerSocket createServerSocket(int port, int backlog) throws IOException {
71 return this.init(this.context.getServerSocketFactory().createServerSocket(port, backlog));
72 }
73
74 public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException {
75 return this.init(this.context.getServerSocketFactory().createServerSocket(port, backlog, ifAddress));
76 }
77
78 public ServerSocket init(ServerSocket socket) throws IOException {
79 ((SSLServerSocket) socket).setUseClientMode(true);
80 return socket;
81 }
82 }