`
l120974020
  • 浏览: 58322 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

apache FTPS文件上传

 
阅读更多
boolean canConnection = false;
		boolean isConnectionSuccess = false;
		FTPSClient ftpsClient = null;
		
		try 
		{
			ftpsClient = new FTPSClient("SSL");
			ftpsClient.setConnectTimeout(300000);	//连接超时为5分钟
			ftpsClient.setDataTimeout(3600000);
			
			ftpsClient.connect(serverIP);
			
//			loger.info(traceStr+"Connected to " + serverIP + ".");
			
			int reply = ftpsClient.getReplyCode();
			
			canConnection = FTPReply.isPositiveCompletion(reply);  //可以判断是否可以连接
//			loger.info(""+"是否可以连接:"+canConnection);
			
			if(canConnection)
			{
				isConnectionSuccess = ftpsClient.login(serverName, password);
				if(!isConnectionSuccess)
				{
					System.out.println("服务器连接错误,请重新配置!");
				}
				else
				{
					System.out.println("连接服务器成功......");
				}
					
			}
			
		} catch (SocketException e) {
			e.printStackTrace();
			
		} catch (IOException e) {
			e.printStackTrace();
			
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
			
		}

boolean isUpLoadSuccess = false;
		File file = new File(clientFilePath);
		System.out.println("上传文件之前大小:"+file.length()/1024.);
		
		FileInputStream input = null; 
		try {
			
			input = new FileInputStream(clientFilePath);
			ftpsClient.enterLocalPassiveMode();
			isUpLoadSuccess = ftpsClient.storeFile(serverPath, input); 
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			
		} catch (IOException e) {
			e.printStackTrace();
			
		}
		finally
		{
			if(null!=input)
			{
				try {
					input.close();
				} catch (IOException e) {
					e.printStackTrace();
					
				}
			}
		}
 
 
分享到:
评论
3 楼 zhengyong7232 2012-12-14  
  truststoreType = "JKS";

        ssltype = "TLS";
        caType = "ca";
        alg = "SunX509";
2 楼 zhengyong7232 2012-12-14  
   tmf.init(truststore);
            TrustManager[] tms = tmf.getTrustManagers();

            ftpsClient.setTrustManager(tms[0]); return ftpsClient;
1 楼 zhengyong7232 2012-12-14  
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
            keyStore.load(new FileInputStream(keystoreFile), keystorePass
                    .toCharArray());

            java.security.cert.Certificate ca = keyStore.getCertificate(caType);
    KeyManagerFactory kmf = KeyManagerFactory.getInstance(alg);
            kmf.init(keyStore, keystorePass.toCharArray());
            KeyManager[] kms = kmf.getKeyManagers();
            ftpsClient.setKeyManager(kms[0]);

相关推荐

Global site tag (gtag.js) - Google Analytics