ftpclient.java
来自「apache推出的net包」· Java 代码 · 共 1,527 行 · 第 1/5 页
JAVA
1,527 行
* <p> * @return True if verification is enabled, false if not. ***/ public boolean isRemoteVerificationEnabled() { return __remoteVerificationEnabled; } /*** * Login to the FTP server using the provided username and password. * <p> * @param username The username to login under. * @param password The password to use. * @return True if successfully completed, false if not. * @exception FTPConnectionClosedException * If the FTP server prematurely closes the connection as a result * of the client being idle or some other reason causing the server * to send FTP reply code 421. This exception may be caught either * as an IOException or independently as itself. * @exception IOException If an I/O error occurs while either sending a * command to the server or receiving a reply from the server. ***/ public boolean login(String username, String password) throws IOException { user(username); if (FTPReply.isPositiveCompletion(_replyCode)) return true; // If we get here, we either have an error code, or an intermmediate // reply requesting password. if (!FTPReply.isPositiveIntermediate(_replyCode)) return false; return FTPReply.isPositiveCompletion(pass(password)); } /*** * Login to the FTP server using the provided username, password, * and account. If no account is required by the server, only * the username and password, the account information is not used. * <p> * @param username The username to login under. * @param password The password to use. * @param account The account to use. * @return True if successfully completed, false if not. * @exception FTPConnectionClosedException * If the FTP server prematurely closes the connection as a result * of the client being idle or some other reason causing the server * to send FTP reply code 421. This exception may be caught either * as an IOException or independently as itself. * @exception IOException If an I/O error occurs while either sending a * command to the server or receiving a reply from the server. ***/ public boolean login(String username, String password, String account) throws IOException { user(username); if (FTPReply.isPositiveCompletion(_replyCode)) return true; // If we get here, we either have an error code, or an intermmediate // reply requesting password. if (!FTPReply.isPositiveIntermediate(_replyCode)) return false; pass(password); if (FTPReply.isPositiveCompletion(_replyCode)) return true; if (!FTPReply.isPositiveIntermediate(_replyCode)) return false; return FTPReply.isPositiveCompletion(acct(account)); } /*** * Logout of the FTP server by sending the QUIT command. * <p> * @return True if successfully completed, false if not. * @exception FTPConnectionClosedException * If the FTP server prematurely closes the connection as a result * of the client being idle or some other reason causing the server * to send FTP reply code 421. This exception may be caught either * as an IOException or independently as itself. * @exception IOException If an I/O error occurs while either sending a * command to the server or receiving a reply from the server. ***/ public boolean logout() throws IOException { return FTPReply.isPositiveCompletion(quit()); } /*** * Change the current working directory of the FTP session. * <p> * @param pathname The new current working directory. * @return True if successfully completed, false if not. * @exception FTPConnectionClosedException * If the FTP server prematurely closes the connection as a result * of the client being idle or some other reason causing the server * to send FTP reply code 421. This exception may be caught either * as an IOException or independently as itself. * @exception IOException If an I/O error occurs while either sending a * command to the server or receiving a reply from the server. ***/ public boolean changeWorkingDirectory(String pathname) throws IOException { return FTPReply.isPositiveCompletion(cwd(pathname)); } /*** * Change to the parent directory of the current working directory. * <p> * @return True if successfully completed, false if not. * @exception FTPConnectionClosedException * If the FTP server prematurely closes the connection as a result * of the client being idle or some other reason causing the server * to send FTP reply code 421. This exception may be caught either * as an IOException or independently as itself. * @exception IOException If an I/O error occurs while either sending a * command to the server or receiving a reply from the server. ***/ public boolean changeToParentDirectory() throws IOException { return FTPReply.isPositiveCompletion(cdup()); } /*** * Issue the FTP SMNT command. * <p> * @param pathname The pathname to mount. * @return True if successfully completed, false if not. * @exception FTPConnectionClosedException * If the FTP server prematurely closes the connection as a result * of the client being idle or some other reason causing the server * to send FTP reply code 421. This exception may be caught either * as an IOException or independently as itself. * @exception IOException If an I/O error occurs while either sending a * command to the server or receiving a reply from the server. ***/ public boolean structureMount(String pathname) throws IOException { return FTPReply.isPositiveCompletion(smnt(pathname)); } /*** * Reinitialize the FTP session. Not all FTP servers support this * command, which issues the FTP REIN command. * <p> * @return True if successfully completed, false if not. * @exception FTPConnectionClosedException * If the FTP server prematurely closes the connection as a result * of the client being idle or some other reason causing the server * to send FTP reply code 421. This exception may be caught either * as an IOException or independently as itself. * @exception IOException If an I/O error occurs while either sending a * command to the server or receiving a reply from the server. ***/ boolean reinitialize() throws IOException { rein(); if (FTPReply.isPositiveCompletion(_replyCode) || (FTPReply.isPositivePreliminary(_replyCode) && FTPReply.isPositiveCompletion(getReply()))) { __initDefaults(); return true; } return false; } /*** * Set the current data connection mode to * <code>ACTIVE_LOCAL_DATA_CONNECTION_MODE</code>. No communication * with the FTP server is conducted, but this causes all future data * transfers to require the FTP server to connect to the client's * data port. Additionally, to accommodate differences between socket * implementations on different platforms, this method causes the * client to issue a PORT command before every data transfer. ***/ public void enterLocalActiveMode() { __dataConnectionMode = ACTIVE_LOCAL_DATA_CONNECTION_MODE; __passiveHost = null; __passivePort = -1; } /*** * Set the current data connection mode to * <code> PASSIVE_LOCAL_DATA_CONNECTION_MODE </code>. Use this * method only for data transfers between the client and server. * This method causes a PASV command to be issued to the server * before the opening of every data connection, telling the server to * open a data port to which the client will connect to conduct * data transfers. The FTPClient will stay in * <code> PASSIVE_LOCAL_DATA_CONNECTION_MODE </code> until the * mode is changed by calling some other method such as * {@link #enterLocalActiveMode enterLocalActiveMode() } ***/ public void enterLocalPassiveMode() { __dataConnectionMode = PASSIVE_LOCAL_DATA_CONNECTION_MODE; // These will be set when just before a data connection is opened // in _openDataConnection_() __passiveHost = null; __passivePort = -1; } /*** * Set the current data connection mode to * <code> ACTIVE_REMOTE_DATA_CONNECTION </code>. Use this method only * for server to server data transfers. This method issues a PORT * command to the server, indicating the other server and port to which * it should connect for data transfers. You must call this method * before EVERY server to server transfer attempt. The FTPClient will * NOT automatically continue to issue PORT commands. You also * must remember to call * {@link #enterLocalActiveMode enterLocalActiveMode() } if you * wish to return to the normal data connection mode. * <p> * @param host The passive mode server accepting connections for data * transfers. * @param port The passive mode server's data port. * @return True if successfully completed, false if not. * @exception FTPConnectionClosedException * If the FTP server prematurely closes the connection as a result * of the client being idle or some other reason causing the server * to send FTP reply code 421. This exception may be caught either * as an IOException or independently as itself. * @exception IOException If an I/O error occurs while either sending a * command to the server or receiving a reply from the server. ***/ public boolean enterRemoteActiveMode(InetAddress host, int port) throws IOException { if (FTPReply.isPositiveCompletion(port(host, port))) { __dataConnectionMode = ACTIVE_REMOTE_DATA_CONNECTION_MODE; __passiveHost = null; __passivePort = -1; return true; } return false; } /*** * Set the current data connection mode to * <code> PASSIVE_REMOTE_DATA_CONNECTION_MODE </code>. Use this * method only for server to server data transfers. * This method issues a PASV command to the server, telling it to * open a data port to which the active server will connect to conduct * data transfers. You must call this method * before EVERY server to server transfer attempt. The FTPClient will * NOT automatically continue to issue PASV commands. You also * must remember to call * {@link #enterLocalActiveMode enterLocalActiveMode() } if you * wish to return to the normal data connection mode. * <p> * @return True if successfully completed, false if not. * @exception FTPConnectionClosedException * If the FTP server prematurely closes the connection as a result * of the client being idle or some other reason causing the server * to send FTP reply code 421. This exception may be caught either * as an IOException or independently as itself. * @exception IOException If an I/O error occurs while either sending a * command to the server or receiving a reply from the server. ***/ public boolean enterRemotePassiveMode() throws IOException { if (pasv() != FTPReply.ENTERING_PASSIVE_MODE) return false; __dataConnectionMode = PASSIVE_REMOTE_DATA_CONNECTION_MODE; __parsePassiveModeReply((String)_replyLines.elementAt(0)); return true; } /*** * Returns the hostname or IP address (in the form of a string) returned * by the server when entering passive mode. If not in passive mode, * returns null. This method only returns a valid value AFTER a * data connection has been opened after a call to * {@link #enterLocalPassiveMode enterLocalPassiveMode()}. * This is because FTPClient sends a PASV command to the server only * just before opening a data connection, and not when you call * {@link #enterLocalPassiveMode enterLocalPassiveMode()}. * <p> * @return The passive host name if in passive mode, otherwise null. ***/ public String getPassiveHost() {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?