當前位置: 首頁>>代碼示例>>Java>>正文


Java FTPReply.ENTERING_PASSIVE_MODE屬性代碼示例

本文整理匯總了Java中org.apache.commons.net.ftp.FTPReply.ENTERING_PASSIVE_MODE屬性的典型用法代碼示例。如果您正苦於以下問題:Java FTPReply.ENTERING_PASSIVE_MODE屬性的具體用法?Java FTPReply.ENTERING_PASSIVE_MODE怎麽用?Java FTPReply.ENTERING_PASSIVE_MODE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.apache.commons.net.ftp.FTPReply的用法示例。


在下文中一共展示了FTPReply.ENTERING_PASSIVE_MODE屬性的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: __openPassiveDataConnection

/**
 * open a passive data connection socket
 * 
 * @param command
 * @param arg
 * @return
 * @throws IOException
 * @throws FtpExceptionCanNotHaveDataConnection
 */
protected Socket __openPassiveDataConnection(int command, String arg)
    throws IOException, FtpExceptionCanNotHaveDataConnection {
  Socket socket;

  // // 20040317, xing, accommodate ill-behaved servers, see below
  // int port_previous = __passivePort;

  if (pasv() != FTPReply.ENTERING_PASSIVE_MODE)
    throw new FtpExceptionCanNotHaveDataConnection("pasv() failed. "
        + getReplyString());

  try {
    __parsePassiveModeReply(getReplyStrings()[0]);
  } catch (MalformedServerReplyException e) {
    throw new FtpExceptionCanNotHaveDataConnection(e.getMessage());
  }

  // // 20040317, xing, accommodate ill-behaved servers, see above
  // int count = 0;
  // System.err.println("__passivePort "+__passivePort);
  // System.err.println("port_previous "+port_previous);
  // while (__passivePort == port_previous) {
  // // just quit if too many tries. make it an exception here?
  // if (count++ > 10)
  // return null;
  // // slow down further for each new try
  // Thread.sleep(500*count);
  // if (pasv() != FTPReply.ENTERING_PASSIVE_MODE)
  // throw new FtpExceptionCanNotHaveDataConnection(
  // "pasv() failed. " + getReplyString());
  // //return null;
  // try {
  // __parsePassiveModeReply(getReplyStrings()[0]);
  // } catch (MalformedServerReplyException e) {
  // throw new FtpExceptionCanNotHaveDataConnection(e.getMessage());
  // }
  // }

  socket = _socketFactory_.createSocket(__passiveHost, __passivePort);

  if (!FTPReply.isPositivePreliminary(sendCommand(command, arg))) {
    socket.close();
    return null;
  }

  if (__remoteVerificationEnabled && !verifyRemote(socket)) {
    InetAddress host1, host2;

    host1 = socket.getInetAddress();
    host2 = getRemoteAddress();

    socket.close();

    // our precaution
    throw new FtpExceptionCanNotHaveDataConnection(
        "Host attempting data connection " + host1.getHostAddress()
            + " is not same as server " + host2.getHostAddress()
            + " So we intentionally close it for security precaution.");
  }

  if (__dataTimeout >= 0)
    socket.setSoTimeout(__dataTimeout);

  return socket;
}
 
開發者ID:jorcox,項目名稱:GeoCrawler,代碼行數:74,代碼來源:Client.java

示例2: __openPassiveDataConnection

protected Socket __openPassiveDataConnection(int command, String arg)
      throws IOException, FtpExceptionCanNotHaveDataConnection {
        Socket socket;

//        // 20040317, xing, accommodate ill-behaved servers, see below
//        int port_previous = __passivePort;

        if (pasv() != FTPReply.ENTERING_PASSIVE_MODE)
          throw new FtpExceptionCanNotHaveDataConnection(
            "pasv() failed. " + getReplyString());

        try {
          __parsePassiveModeReply(getReplyStrings()[0]);
        } catch (MalformedServerReplyException e) {
          throw new FtpExceptionCanNotHaveDataConnection(e.getMessage());
        }

//        // 20040317, xing, accommodate ill-behaved servers, see above
//        int count = 0;
//        System.err.println("__passivePort "+__passivePort);
//        System.err.println("port_previous "+port_previous);
//        while (__passivePort == port_previous) {
//          // just quit if too many tries. make it an exception here?
//          if (count++ > 10)
//            return null;
//          // slow down further for each new try
//          Thread.sleep(500*count);
//          if (pasv() != FTPReply.ENTERING_PASSIVE_MODE)
//            throw new FtpExceptionCanNotHaveDataConnection(
//              "pasv() failed. " + getReplyString());
//            //return null;
//          try {
//            __parsePassiveModeReply(getReplyStrings()[0]);
//          } catch (MalformedServerReplyException e) {
//            throw new FtpExceptionCanNotHaveDataConnection(e.getMessage());
//          }
//        }

        socket = _socketFactory_.createSocket(__passiveHost, __passivePort);

        if (!FTPReply.isPositivePreliminary(sendCommand(command, arg))) {
          socket.close();
          return null;
        }

        if (__remoteVerificationEnabled && !verifyRemote(socket))
        {
            InetAddress host1, host2;

            host1 = socket.getInetAddress();
            host2 = getRemoteAddress();

            socket.close();

            // our precaution
            throw new FtpExceptionCanNotHaveDataConnection(
                "Host attempting data connection " + host1.getHostAddress() +
                " is not same as server " + host2.getHostAddress() +
                " So we intentionally close it for security precaution."
                );
        }

        if (__dataTimeout >= 0)
            socket.setSoTimeout(__dataTimeout);

        return socket;
    }
 
開發者ID:yahoo,項目名稱:anthelion,代碼行數:67,代碼來源:Client.java

示例3: pasv

public int pasv() throws IOException {
	int passiveReturnCode = super.pasv();

	if (passiveReturnCode == FTPReply.ENTERING_PASSIVE_MODE) {

		// Parse and display reply host and port in passive mode
		// It's quite ugly but there is no entry point in apache's ftp library to perform this check.
		String reply = getReplyStrings()[0];
		int i, index, lastIndex;
		String octet1, octet2;
		StringBuffer host;

		reply = reply.substring(reply.indexOf('(') + 1, reply.indexOf(')')).trim();

		host = new StringBuffer(24);
		lastIndex = 0;
		index = reply.indexOf(',');
		host.append(reply.substring(lastIndex, index));

		for (i = 0; i < 3; i++) {
			host.append('.');
			lastIndex = index + 1;
			index = reply.indexOf(',', lastIndex);
			host.append(reply.substring(lastIndex, index));
		}

		lastIndex = index + 1;
		index = reply.indexOf(',', lastIndex);

		octet1 = reply.substring(lastIndex, index);
		octet2 = reply.substring(index + 1);

		// index and lastIndex now used as temporaries
		try {
			index = Integer.parseInt(octet1);
			lastIndex = Integer.parseInt(octet2);
		} catch (NumberFormatException e) {
			throw new MalformedServerReplyException("Could not parse passive host information.\nServer Reply: " + reply);
		}

		index <<= 8;
		index |= lastIndex;

		String passvHost = host.toString();

		//int passvPort = index;
		//Logger.defaultLogger().info("Passive host received from server : " + passvHost + ":" + passvPort);

		InetAddress refAddress = InetAddress.getByName(passvHost);
		if (! refAddress.equals(this._socket_.getInetAddress())) {
			String msg = "Passive address (" + refAddress + ") differs from host address (" + this._socket_.getInetAddress() + "). This is probably because your server is behind a router. Please check your FTP server's configuration. (for instance, use a masquerade address)";
			Logger.defaultLogger().warn(msg);
			if (! ignorePasvErrors) {
				throw new IOException(msg);
			}
		}
	}

	return passiveReturnCode;
}
 
開發者ID:chfoo,項目名稱:areca-backup-release-mirror,代碼行數:60,代碼來源:FTPClient.java


注:本文中的org.apache.commons.net.ftp.FTPReply.ENTERING_PASSIVE_MODE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。