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 package com.mindtree.techworks.insight.download;
26
27 import java.net.MalformedURLException;
28 import java.net.PasswordAuthentication;
29 import java.net.URL;
30
31
32
33
34
35
36
37
38
39
40 public class SFTPFileset extends Fileset {
41
42
43
44
45
46
47
48
49 public static final String SFTP_PROTOCOL = "sftp";
50
51
52
53
54 public static final int SFTP_DEFAULT_PORT = 22;
55
56
57
58
59
60
61
62
63 private String host;
64
65
66
67
68
69 private int port = SFTP_DEFAULT_PORT;
70
71
72
73
74 private String defaultDirectory;
75
76
77
78
79 private boolean isAuthenticationRequired;
80
81
82
83
84
85 private String userName;
86
87
88
89
90
91 private String password;
92
93
94
95
96 private boolean isProxyRequired;
97
98
99
100
101
102
103
104
105
106
107 public SFTPFileset (String filesetName) {
108
109 super(filesetName, Fileset.SFTP_FILESET, "SFTP_CLIENT");
110 }
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125 public SFTPFileset (String filesetName, String host, int port,
126 String defaultDirectory, boolean isAuthenticationRequired,
127 String userName, String password, boolean isProxyRequired) {
128
129 super(filesetName, Fileset.SFTP_FILESET, "SFTP_CLIENT");
130 this.host = host;
131 this.port = port;
132 this.defaultDirectory = defaultDirectory;
133 this.isAuthenticationRequired = isAuthenticationRequired;
134 this.userName = userName;
135 this.password = password;
136 this.isProxyRequired = isProxyRequired;
137 }
138
139
140
141
142
143
144
145
146 public String getDefaultDirectory () {
147
148 return defaultDirectory;
149 }
150
151
152
153
154 public void setDefaultDirectory (String defaultDirectory) {
155
156 this.defaultDirectory = defaultDirectory;
157 }
158
159
160
161
162 public String getHost () {
163
164 return host;
165 }
166
167
168
169
170 public void setHost (String host) {
171
172 this.host = host;
173 }
174
175
176
177
178 public boolean isAuthenticationRequired () {
179
180 return isAuthenticationRequired;
181 }
182
183
184
185
186 public void setAuthenticationRequired (boolean isAuthenticationRequired) {
187
188 this.isAuthenticationRequired = isAuthenticationRequired;
189 }
190
191
192
193
194 public boolean isProxyRequired () {
195
196 return isProxyRequired;
197 }
198
199
200
201
202 public void setProxyRequired (boolean isProxyRequired) {
203
204 this.isProxyRequired = isProxyRequired;
205 }
206
207
208
209
210 public String getPassword () {
211
212 return password;
213 }
214
215
216
217
218 public void setPassword (String password) {
219
220 this.password = password;
221 }
222
223
224
225
226 public int getPort () {
227
228 return port;
229 }
230
231
232
233
234 public void setPort (int port) {
235
236 this.port = port;
237 }
238
239
240
241
242 public String getUserName () {
243
244 return userName;
245 }
246
247
248
249
250 public void setUserName (String userName) {
251
252 this.userName = userName;
253 }
254
255
256
257
258
259
260
261
262
263
264
265 public URL getHostURL () throws MalformedURLException {
266
267 URL hostURL = null;
268 if (null == defaultDirectory) {
269 hostURL = new URL(SFTP_PROTOCOL, host, port, "");
270 } else {
271 hostURL = new URL(SFTP_PROTOCOL, host, port, defaultDirectory);
272 }
273 return hostURL;
274 }
275
276
277
278
279
280
281
282
283
284 public PasswordAuthentication getPasswordAuthentication () {
285
286 if (isAuthenticationRequired && null != userName && null != password) {
287 return new PasswordAuthentication(userName, password.toCharArray());
288 } else {
289 return null;
290 }
291 }
292 }