Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private FTPSClient ftp = new FTPSClient();
- private KeyStore loadStore(String storeType, File storePath, String storePass)
- throws KeyStoreException, IOException, GeneralSecurityException {
- KeyStore ks = KeyStore.getInstance(storeType);
- FileInputStream stream = null;
- try {
- stream = new FileInputStream(storePath);
- ks.load(stream, storePass.toCharArray());
- } finally {
- Util.closeQuietly(stream);
- }
- return ks;
- }
- public boolean connect() throws FTPException {
- boolean result = false;
- FTPClientConfig config = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
- {
- // config.set
- }
- try {
- System.out.println("FTPS connecting...");
- //ftp.configure(config);
- System.out.println(connectInfo.get(FTP.HOST)+", "+connectInfo.get(FTP.PORT));
- //ftp.connect(connectInfo.get(FTP.HOST));
- File storeFile = new File("C:\Users\Administrator\Desktop\MOCOMSYS\====WORK====\MI\ETC\tmp\vsftpd.p12");
- KeyStore keyStore=null;
- X509TrustManager defaultTrustManager=null;
- try {
- keyStore = loadStore("JKS", storeFile, "mocomsys1");
- defaultTrustManager = TrustManagerUtils.getDefaultTrustManager(keyStore);
- } catch (KeyStoreException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (GeneralSecurityException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- //******whatever i use trustmanager or not, i can access 21port and cant access 990 port.******
- //ftp.setTrustManager(defaultTrustManager);
- ftp.connect(connectInfo.get(FTP.HOST), Integer.parseInt(connectInfo.get(FTP.PORT)));
- System.out.println(FTPReply.isPositiveCompletion(ftp.getReplyCode()));
- ftp.setSoLinger(true, 1000);
- ftp.setSoTimeout(Integer.parseInt(connectInfo.get(FTP.TIMEOUT)));
- System.out.println("~~~~~~~~~~~~~~~~~~");
- System.out.println(ftp.getAuthValue());
- System.out.println(ftp.getLocalPort());
- System.out.println(ftp.getPassivePort());
- System.out.println(ftp.getRemotePort());
- System.out.println(ftp.getSystemName());
- System.out.println(ftp.getSystemType());
- System.out.println(ftp.getRemoteAddress());
- result = ftp.login(connectInfo.get(FTP.USERNAME), connectInfo.get(FTP.PASSWORD));
- ftp.execPBSZ(0);
- ftp.execPROT("P");
- ftp.enterLocalPassiveMode();
- System.out.println("FTPS connection : "+result);
- // FileEntryParser
- } catch (NumberFormatException e) {
- throw new FTPException(e);
- } catch (SocketException e) {
- throw new FTPException(e);
- } catch (IOException e) {
- throw new FTPException(e);
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement