ftpclient.java

来自「apache推出的net包」· Java 代码 · 共 1,527 行 · 第 1/5 页

JAVA
1,527
字号
        return __passiveHost;    }    /***     * If in passive mode, returns the data port of the passive host.     * 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 data port of the passive server.  If not in passive     *         mode, undefined.     ***/    public int getPassivePort()    {        return __passivePort;    }    /***     * Returns the current data connection mode (one of the     * <code> _DATA_CONNECTION_MODE </code> constants.     * <p>     * @return The current data connection mode (one of the     * <code> _DATA_CONNECTION_MODE </code> constants.     ***/    public int getDataConnectionMode()    {        return __dataConnectionMode;    }    /***     * Sets the file type to be transferred.  This should be one of     * <code> FTP.ASCII_FILE_TYPE </code>, <code> FTP.IMAGE_FILE_TYPE </code>,     * etc.  The file type only needs to be set when you want to change the     * type.  After changing it, the new type stays in effect until you change     * it again.  The default file type is <code> FTP.ASCII_FILE_TYPE </code>     * if this method is never called.     * <p>     * @param fileType The <code> _FILE_TYPE </code> constant indcating the     *                 type of file.     * @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 setFileType(int fileType) throws IOException    {        if (FTPReply.isPositiveCompletion(type(fileType)))        {            __fileType = fileType;            __fileFormat = FTP.NON_PRINT_TEXT_FORMAT;            return true;        }        return false;    }    /***     * Sets the file type to be transferred and the format.  The type should be     * one of  <code> FTP.ASCII_FILE_TYPE </code>,     * <code> FTP.IMAGE_FILE_TYPE </code>, etc.  The file type only needs to     * be set when you want to change the type.  After changing it, the new     * type stays in effect until you change it again.  The default file type     * is <code> FTP.ASCII_FILE_TYPE </code> if this method is never called.     * The format should be one of the FTP class <code> TEXT_FORMAT </code>     * constants, or if the type is <code> FTP.LOCAL_FILE_TYPE </code>, the     * format should be the byte size for that type.  The default format     * is <code> FTP.NON_PRINT_TEXT_FORMAT </code> if this method is never     * called.     * <p>     * @param fileType The <code> _FILE_TYPE </code> constant indcating the     *                 type of file.     * @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.     * <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 setFileType(int fileType, int formatOrByteSize)    throws IOException    {        if (FTPReply.isPositiveCompletion(type(fileType, formatOrByteSize)))        {            __fileType = fileType;            __fileFormat = formatOrByteSize;            return true;        }        return false;    }    /***     * Sets the file structure.  The default structure is     * <code> FTP.FILE_STRUCTURE </code> if this method is never called.     * <p>     * @param structure  The structure of the file (one of the FTP class     *         <code>_STRUCTURE</code> constants).     * @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 setFileStructure(int structure) throws IOException    {        if (FTPReply.isPositiveCompletion(stru(structure)))        {            __fileStructure = structure;            return true;        }        return false;    }    /***     * Sets the transfer mode.  The default transfer mode     * <code> FTP.STREAM_TRANSFER_MODE </code> if this method is never called.     * <p>     * @param mode  The new transfer mode to use (one of the FTP class     *         <code>_TRANSFER_MODE</code> constants).     * @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 setFileTransferMode(int mode) throws IOException    {        if (FTPReply.isPositiveCompletion(mode(mode)))        {            __fileTransferMode = mode;            return true;        }        return false;    }    /***     * Initiate a server to server file transfer.  This method tells the     * server to which the client is connected to retrieve a given file from     * the other server.     * <p>     * @param filename  The name of the file to retrieve.     * @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 remoteRetrieve(String filename) throws IOException    {        if (__dataConnectionMode == ACTIVE_REMOTE_DATA_CONNECTION_MODE ||                __dataConnectionMode == PASSIVE_REMOTE_DATA_CONNECTION_MODE)            return FTPReply.isPositivePreliminary(retr(filename));        return false;    }    /***     * Initiate a server to server file transfer.  This method tells the     * server to which the client is connected to store a file on     * the other server using the given filename.  The other server must     * have had a <code> remoteRetrieve </code> issued to it by another     * FTPClient.     * <p>     * @param filename  The name to call the file that is to be stored.     * @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 remoteStore(String filename) throws IOException    {        if (__dataConnectionMode == ACTIVE_REMOTE_DATA_CONNECTION_MODE ||                __dataConnectionMode == PASSIVE_REMOTE_DATA_CONNECTION_MODE)            return FTPReply.isPositivePreliminary(stor(filename));        return false;    }    /***     * Initiate a server to server file transfer.  This method tells the     * server to which the client is connected to store a file on     * the other server using a unique filename based on the given filename.     * The other server must have had a <code> remoteRetrieve </code> issued     * to it by another FTPClient.     * <p>     * @param filename  The name on which to base the filename of the file     *                  that is to be stored.     * @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 remoteStoreUnique(String filename) throws IOException    {        if (__dataConnectionMode == ACTIVE_REMOTE_DATA_CONNECTION_MODE ||                __dataConnectionMode == PASSIVE_REMOTE_DATA_CONNECTION_MODE)            return FTPReply.isPositivePreliminary(stou(filename));        return false;    }    /***     * Initiate a server to server file transfer.  This method tells the     * server to which the client is connected to store a file on     * the other server using a unique filename.     * The other server must have had a <code> remoteRetrieve </code> issued     * to it by another FTPClient.  Many FTP servers require that a base     * filename be given from which the unique filename can be derived.  For     * those servers use the other version of <code> remoteStoreUnique</code>     * <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 remoteStoreUnique() throws IOException    {        if (__dataConnectionMode == ACTIVE_REMOTE_DATA_CONNECTION_MODE ||                __dataConnectionMode == PASSIVE_REMOTE_DATA_CONNECTION_MODE)            return FTPReply.isPositivePreliminary(stou());        return false;    }    // For server to server transfers    /***     * Initiate a server to server file transfer.  This method tells the     * server to which the client is connected to append to a given file on     * the other server.  The other server must have had a     * <code> remoteRetrieve </code> issued to it by another FTPClient.     * <p>     * @param filename  The name of the file to be appended to, or if the     *        file does not exist, the name to call the file being stored.     * <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 remoteAppend(String filename) throws IOException    {        if (__dataConnectionMode == ACTIVE_REMOTE_DATA_CONNECTION_MODE ||                __dataConnectionMode == PASSIVE_REMOTE_DATA_CONNECTION_MODE)            return FTPReply.isPositivePreliminary(stor(filename));        return false;    }    /***     * There are a few FTPClient methods that do not complete the     * entire sequence of FTP commands to complete a transaction.  These     * commands require some action by the programmer after the reception     * of a positive intermediate command.  After the programmer's code     * completes its actions, it must call this method to receive     * the completion reply from the server and verify the success of the     * entire transaction.     * <p>     * For example,     * <pre>     * InputStream input;     * OutputStream output;     * input  = new FileInputStream("foobaz.txt");     * output = ftp.storeFileStream("foobar.txt")     * if(!FTPReply.isPositiveIntermediate(ftp.getReplyCode())) {     *     input.close();     *     output.close();

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?