Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. private FTPSClient ftp = new FTPSClient();
  2.  
  3. private KeyStore loadStore(String storeType, File storePath, String storePass)
  4. throws KeyStoreException, IOException, GeneralSecurityException {
  5. KeyStore ks = KeyStore.getInstance(storeType);
  6. FileInputStream stream = null;
  7. try {
  8. stream = new FileInputStream(storePath);
  9. ks.load(stream, storePass.toCharArray());
  10. } finally {
  11. Util.closeQuietly(stream);
  12. }
  13. return ks;
  14. }
  15. public boolean connect() throws FTPException {
  16.  
  17. boolean result = false;
  18.  
  19. FTPClientConfig config = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
  20. {
  21. // config.set
  22. }
  23.  
  24. try {
  25.  
  26. System.out.println("FTPS connecting...");
  27. //ftp.configure(config);
  28. System.out.println(connectInfo.get(FTP.HOST)+", "+connectInfo.get(FTP.PORT));
  29. //ftp.connect(connectInfo.get(FTP.HOST));
  30.  
  31. File storeFile = new File("C:\Users\Administrator\Desktop\MOCOMSYS\====WORK====\MI\ETC\tmp\vsftpd.p12");
  32.  
  33. KeyStore keyStore=null;
  34. X509TrustManager defaultTrustManager=null;
  35. try {
  36. keyStore = loadStore("JKS", storeFile, "mocomsys1");
  37. defaultTrustManager = TrustManagerUtils.getDefaultTrustManager(keyStore);
  38. } catch (KeyStoreException e) {
  39. // TODO Auto-generated catch block
  40. e.printStackTrace();
  41. } catch (GeneralSecurityException e) {
  42. // TODO Auto-generated catch block
  43. e.printStackTrace();
  44. }
  45. //******whatever i use trustmanager or not, i can access 21port and cant access 990 port.******
  46. //ftp.setTrustManager(defaultTrustManager);
  47.  
  48. ftp.connect(connectInfo.get(FTP.HOST), Integer.parseInt(connectInfo.get(FTP.PORT)));
  49. System.out.println(FTPReply.isPositiveCompletion(ftp.getReplyCode()));
  50.  
  51. ftp.setSoLinger(true, 1000);
  52. ftp.setSoTimeout(Integer.parseInt(connectInfo.get(FTP.TIMEOUT)));
  53. System.out.println("~~~~~~~~~~~~~~~~~~");
  54. System.out.println(ftp.getAuthValue());
  55. System.out.println(ftp.getLocalPort());
  56. System.out.println(ftp.getPassivePort());
  57. System.out.println(ftp.getRemotePort());
  58. System.out.println(ftp.getSystemName());
  59. System.out.println(ftp.getSystemType());
  60. System.out.println(ftp.getRemoteAddress());
  61.  
  62.  
  63. result = ftp.login(connectInfo.get(FTP.USERNAME), connectInfo.get(FTP.PASSWORD));
  64.  
  65. ftp.execPBSZ(0);
  66. ftp.execPROT("P");
  67. ftp.enterLocalPassiveMode();
  68.  
  69. System.out.println("FTPS connection : "+result);
  70. // FileEntryParser
  71.  
  72. } catch (NumberFormatException e) {
  73. throw new FTPException(e);
  74. } catch (SocketException e) {
  75. throw new FTPException(e);
  76. } catch (IOException e) {
  77. throw new FTPException(e);
  78. }
  79.  
  80. return result;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement