ftp.java
来自「apache推出的net包」· Java 代码 · 共 1,475 行 · 第 1/5 页
JAVA
1,475 行
* method if you are implementing your own FTP client or if you need to * fetch a secondary response from the FTP server. * <p> * @return The integer value of the reply code of the fetched FTP reply. * @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 receiving the * server reply. ***/ public int getReply() throws IOException { __getReply(); return _replyCode; } /*** * Returns the lines of text from the last FTP server response as an array * of strings, one entry per line. The end of line markers of each are * stripped from each line. * <p> * @return The lines of text from the last FTP response as an array. ***/ public String[] getReplyStrings() { String[] lines; lines = new String[_replyLines.size()]; _replyLines.copyInto(lines); return lines; } /*** * Returns the entire text of the last FTP server response exactly * as it was received, including all end of line markers in NETASCII * format. * <p> * @return The entire text from the last FTP response as a String. ***/ public String getReplyString() { Enumeration en; StringBuffer buffer; if (!_newReplyString) return _replyString; buffer = new StringBuffer(256); en = _replyLines.elements(); while (en.hasMoreElements()) { buffer.append((String)en.nextElement()); buffer.append(SocketClient.NETASCII_EOL); } _newReplyString = false; return (_replyString = buffer.toString()); } /*** * A convenience method to send the FTP USER command to the server, * receive the reply, and return the reply code. * <p> * @param username The username to login under. * @return The reply code received from the server. * @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 the * command or receiving the server reply. ***/ public int user(String username) throws IOException { return sendCommand(FTPCommand.USER, username); } /** * A convenience method to send the FTP PASS command to the server, * receive the reply, and return the reply code. * @param password The plain text password of the username being logged into. * @return The reply code received from the server. * @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 the * command or receiving the server reply. */ public int pass(String password) throws IOException { return sendCommand(FTPCommand.PASS, password); } /*** * A convenience method to send the FTP ACCT command to the server, * receive the reply, and return the reply code. * <p> * @param account The account name to access. * @return The reply code received from the server. * @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 the * command or receiving the server reply. ***/ public int acct(String account) throws IOException { return sendCommand(FTPCommand.ACCT, account); } /*** * A convenience method to send the FTP ABOR command to the server, * receive the reply, and return the reply code. * <p> * @return The reply code received from the server. * @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 the * command or receiving the server reply. ***/ public int abor() throws IOException { return sendCommand(FTPCommand.ABOR); } /*** * A convenience method to send the FTP CWD command to the server, * receive the reply, and return the reply code. * <p> * @param directory The new working directory. * @return The reply code received from the server. * @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 the * command or receiving the server reply. ***/ public int cwd(String directory) throws IOException { return sendCommand(FTPCommand.CWD, directory); } /*** * A convenience method to send the FTP CDUP command to the server, * receive the reply, and return the reply code. * <p> * @return The reply code received from the server. * @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 the * command or receiving the server reply. ***/ public int cdup() throws IOException { return sendCommand(FTPCommand.CDUP); } /*** * A convenience method to send the FTP QUIT command to the server, * receive the reply, and return the reply code. * <p> * @return The reply code received from the server. * @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 the * command or receiving the server reply. ***/ public int quit() throws IOException { return sendCommand(FTPCommand.QUIT); } /*** * A convenience method to send the FTP REIN command to the server, * receive the reply, and return the reply code. * <p> * @return The reply code received from the server. * @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 the * command or receiving the server reply. ***/ public int rein() throws IOException { return sendCommand(FTPCommand.REIN); } /*** * A convenience method to send the FTP SMNT command to the server, * receive the reply, and return the reply code. * <p> * @param dir The directory name. * @return The reply code received from the server. * @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 the * command or receiving the server reply. ***/ public int smnt(String dir) throws IOException { return sendCommand(FTPCommand.SMNT, dir); } /*** * A convenience method to send the FTP PORT command to the server, * receive the reply, and return the reply code. * <p> * @param host The host owning the port. * @param port The new port. * @return The reply code received from the server. * @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 the * command or receiving the server reply. ***/ public int port(InetAddress host, int port) throws IOException { int num; StringBuffer info = new StringBuffer(24); info.append(host.getHostAddress().replace('.', ',')); num = port >>> 8; info.append(','); info.append(num); info.append(','); num = port & 0xff; info.append(num); return sendCommand(FTPCommand.PORT, info.toString()); } /*** * A convenience method to send the FTP PASV command to the server, * receive the reply, and return the reply code. Remember, it's up * to you to interpret the reply string containing the host/port * information. * <p> * @return The reply code received from the server. * @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 the * command or receiving the server reply. ***/ public int pasv() throws IOException { return sendCommand(FTPCommand.PASV); } /** * A convenience method to send the FTP TYPE command for text files * to the server, receive the reply, and return the reply code. * @param fileType The type of the file (one of the <code>FILE_TYPE</code> * constants). * @param formatOrByteSize The format of the file (one of the * <code>_FORMAT</code> constants. In the case of * <code>LOCAL_FILE_TYPE</code>, the byte size. * @return The reply code received from the server. * @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.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?