Project

General

Profile

« Previous | Next » 

Revision 61774

support of FTPS

View differences:

modules/dnet-isti/trunk/src/main/java/eu/dnetlib/data/mdstore/plugins/EnrichLocalLinksPlugin.java
14 14
import org.apache.commons.logging.LogFactory;
15 15
import org.apache.commons.net.ftp.FTPClient;
16 16
import org.apache.commons.net.ftp.FTPFile;
17
import org.apache.commons.net.ftp.FTPSClient;
17 18

  
18 19
import com.google.common.net.UrlEscapers;
19 20

  
......
28 29

  
29 30
	private static final Log log = LogFactory.getLog(EnrichLocalLinksPlugin.class);
30 31

  
31
	private FTPClient ftpClient = new FTPClient();
32
	private FTPClient ftpClient;
32 33

  
33 34
	private String hostedBy;
34 35
	private String baseUrl;
......
52 53
		}
53 54

  
54 55
		try {
56
			ftpClient = new FTPSClient();
55 57
			ftpClient.connect(getFtpServer());
56
			ftpClient.login(getFtpUser(), getFtpPassword());
58
			// Set protection buffer size
59
			((FTPSClient) ftpClient).execPBSZ(0);
60
			// Set data channel protection to private
61
			((FTPSClient) ftpClient).execPROT("P");
57 62

  
63
			if (!ftpClient.login(getFtpUser(), getFtpPassword())) {
64
				// I RETRY USING not secure FTP
65
				ftpClient = new FTPClient();
66
				ftpClient.connect(getFtpServer());
67
				if (!ftpClient.login(getFtpUser(), getFtpPassword())) { throw new RuntimeException("FTP login failed"); }
68
			}
69

  
58 70
			ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
59 71
			ftpClient.enterLocalPassiveMode();
60 72
			ftpClient.setBufferSize(1024);
......
83 95
		setFtpUser(null);
84 96
		setFtpPassword(null);
85 97
		setFtpBaseDir(null);
98
		setFtpClient(null);
86 99
	}
87 100

  
88 101
	@Override
......
124 137
					log.debug(content);
125 138
				}
126 139
				if (!ftpClient.storeFile(INFO_FILENAME, is)) {
127
					log.error("Error saving file");
128
					throw new RuntimeException("Error saving file");
140
					log.error("Error saving file: " + ftpClient.getReplyCode() + " - " + ftpClient.getReplyString());
141
					throw new RuntimeException("Error saving file: " + ftpClient.getReplyString());
129 142
				}
130 143
			} catch (final IOException e) {
131 144
				log.error("Error saving info file");

Also available in: Unified diff