29160c941cce803c96ebf3e3e0d5cad34ba1645d
[dcaegen2/collectors/datafile.git] /
1 /*
2  * ============LICENSE_START======================================================================
3  * Copyright (C) 2018-2019 Nordix Foundation. All rights reserved.
4  * ===============================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6  * in compliance with the License. You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software distributed under the License
11  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12  * or implied. See the License for the specific language governing permissions and limitations under
13  * the License.
14  * ============LICENSE_END========================================================================
15  */
16
17 package org.onap.dcaegen2.collectors.datafile.ftp;
18
19 import java.io.IOException;
20 import java.io.OutputStream;
21 import javax.net.ssl.KeyManager;
22 import javax.net.ssl.TrustManager;
23 import org.apache.commons.net.ftp.FTPSClient;
24 import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
25
26 public class FTPSClientWrapper implements IFTPSClient {
27     private FTPSClient ftpsClient = new FTPSClient();
28
29     @Override
30     public void setNeedClientAuth(boolean isNeedClientAuth) {
31         ftpsClient.setNeedClientAuth(isNeedClientAuth);
32     }
33
34     @Override
35     public void setKeyManager(KeyManager keyManager) {
36         ftpsClient.setKeyManager(keyManager);
37     }
38
39     @Override
40     public void setTrustManager(TrustManager trustManager) {
41         ftpsClient.setTrustManager(trustManager);
42     }
43
44     @Override
45     public void connect(String hostName, int port) throws IOException {
46         ftpsClient.connect(hostName, port);
47     }
48
49     @Override
50     public boolean login(String username, String password) throws IOException {
51         return ftpsClient.login(username, password);
52     }
53
54     @Override
55     public boolean logout() throws IOException {
56         return ftpsClient.logout();
57     }
58
59     @Override
60     public int getReplyCode() {
61         return ftpsClient.getReplyCode();
62     }
63
64     @Override
65     public void disconnect() throws IOException {
66         ftpsClient.disconnect();
67     }
68
69     @Override
70     public void enterLocalPassiveMode() {
71         ftpsClient.enterLocalPassiveMode();
72     }
73
74     @Override
75     public void setFileType(int fileType) throws IOException {
76         ftpsClient.setFileType(fileType);
77     }
78
79     @Override
80     public void execPBSZ(int psbz) throws IOException {
81         ftpsClient.execPBSZ(psbz);
82     }
83
84     @Override
85     public void execPROT(String prot) throws IOException {
86         ftpsClient.execPROT(prot);
87     }
88
89     @Override
90     public void retrieveFile(String remote, OutputStream local) throws DatafileTaskException {
91         try {
92             if (!ftpsClient.retrieveFile(remote, local)) {
93                 throw new DatafileTaskException("could not retrieve file");
94             }
95         } catch (IOException e) {
96             throw new DatafileTaskException(e);
97         }
98     }
99
100     @Override
101     public void setTimeout(Integer t) {
102         this.ftpsClient.setDefaultTimeout(t);
103     }
104
105     @Override
106     public boolean isConnected() {
107         return ftpsClient.isConnected();
108     }
109
110     @Override
111     public void setBufferSize(int bufSize) {
112         ftpsClient.setBufferSize(bufSize);
113     }
114 }