java FTP

JAR包:commons-net-2.0.jar

private boolean getConnection()
	{
		boolean canConnection = false;
		boolean isConnectionSuccess = false;
		
		try 
		{
			FTPClient ftpClient = new FTPClient();
			ftpClient.setConnectTimeout(3600000);	//连接超时为60分钟
			ftpClient.setDataTimeout(3600000);
			
			ftpClient.connect(serverIP);
			
//			loger.info(traceStr+"Connected to " + serverIP + ".");
			
			int reply = ftpClient.getReplyCode();
			
			canConnection = FTPReply.isPositiveCompletion(reply);  //可以判断是否可以连接
//			loger.info(""+"是否可以连接:"+canConnection);
			
			if(canConnection)
			{
				isConnectionSuccess = ftpClient.login(serverName, password);
				if(!isConnectionSuccess)
				{
					loger.info("FTPS第 "+(synchNum+1)+" 轮 服务器连接错误,请重新配置!");
				}
				else
				{
					loger.info("FTPS第 "+(synchNum+1)+" 轮 连接服务器成功......");
				}
					
			}
			
		} catch (SocketException e) {
			ExceptionDispose.printException(e, traceStr, FTPSConnection.class);
			
		} catch (IOException e) {
			ExceptionDispose.printException(e, traceStr, FTPSConnection.class);
			
		} 
		
		return isConnectionSuccess;
	}
 

你可能感兴趣的:(java)