[sdc] update code of sdc
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / execute / setup / TestFtp.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.ci.tests.execute.setup;
22
23 import java.io.BufferedReader;
24 import java.io.File;
25 import java.io.FileReader;
26 import java.io.IOException;
27 import java.nio.charset.StandardCharsets;
28 import java.nio.file.Files;
29 import java.nio.file.Paths;
30
31 public class TestFtp {
32
33         public static void main(String[] args) throws IOException {
34                 AttFtpClient instance = AttFtpClient.getInstance();
35                 
36                  String server = "localhost";
37               int port = 2121;
38               String user = "admin";
39               String pass = "admin";
40               AttFtpClient.getInstance().init(server, port, user, pass);
41               
42               try {
43                   AttFtpClient.getInstance().retrieveListOfFile();
44                   
45                   File retrieveLastModifiedFileFromFTP = instance.retrieveLastModifiedFileFromFTP();
46                   String content = new String(Files.readAllBytes(Paths.get(retrieveLastModifiedFileFromFTP.getPath())), StandardCharsets.UTF_8);
47 //                instance.deleteFilesFromFTPserver();
48                   System.out.println(content);
49                   readFile(retrieveLastModifiedFileFromFTP);
50                         
51                 } finally {
52                         instance.terminateClient();
53                 }
54               
55              
56
57               
58               
59               
60                 
61         }
62          public static void readFile(File retrieveLastModifiedFileFromFTP) {
63
64                 StringBuilder sb = new StringBuilder();
65                 BufferedReader br = null;
66                 FileReader fileReader = null;
67                 try {
68                         fileReader = new FileReader(retrieveLastModifiedFileFromFTP.getPath());
69                     br = new BufferedReader(fileReader);
70                     String line;
71                     while ((line = br.readLine()) != null) {
72                         if (sb.length() > 0) {
73                             sb.append("\n");
74                         }
75                         sb.append(line);
76                     }
77                 } catch (IOException e) {
78                     System.out.println(e);
79                 } finally {
80                     try {
81                         if (br != null) {
82                             br.close();
83                         }
84                         if(fileReader != null) {
85                                 fileReader.close();
86                         }
87                     } catch (IOException ex) {
88                         System.out.println(ex);
89                     }
90                 }
91                 String contents = sb.toString();
92                 System.out.println(contents);           
93                  
94          }
95
96 }