日期:2014-05-17  浏览次数:20765 次

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();
					
				}
			}
		}
?
?