|
|
|
@ -14,8 +14,19 @@ |
|
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
|
* limitations under the License. |
|
|
|
|
*/ |
|
|
|
|
package org.apache.commons.net.ftp; |
|
|
|
|
|
|
|
|
|
package aria.apache.commons.net.ftp; |
|
|
|
|
|
|
|
|
|
import aria.apache.commons.net.SocketClient; |
|
|
|
|
import aria.apache.commons.net.ftp.parser.ParserInitializationException; |
|
|
|
|
import aria.apache.commons.net.io.CopyStreamAdapter; |
|
|
|
|
import aria.apache.commons.net.io.CopyStreamEvent; |
|
|
|
|
import aria.apache.commons.net.io.CopyStreamException; |
|
|
|
|
import aria.apache.commons.net.io.CopyStreamListener; |
|
|
|
|
import aria.apache.commons.net.io.FromNetASCIIInputStream; |
|
|
|
|
import aria.apache.commons.net.io.SocketInputStream; |
|
|
|
|
import aria.apache.commons.net.io.SocketOutputStream; |
|
|
|
|
import aria.apache.commons.net.io.ToNetASCIIOutputStream; |
|
|
|
|
import aria.apache.commons.net.io.Util; |
|
|
|
|
import java.io.BufferedInputStream; |
|
|
|
|
import java.io.BufferedOutputStream; |
|
|
|
|
import java.io.BufferedReader; |
|
|
|
@ -42,28 +53,22 @@ import java.util.Properties; |
|
|
|
|
import java.util.Random; |
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
import org.apache.commons.net.MalformedServerReplyException; |
|
|
|
|
import org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory; |
|
|
|
|
import org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory; |
|
|
|
|
import org.apache.commons.net.ftp.parser.MLSxEntryParser; |
|
|
|
|
import org.apache.commons.net.io.CRLFLineReader; |
|
|
|
|
import org.apache.commons.net.io.CopyStreamAdapter; |
|
|
|
|
import org.apache.commons.net.io.CopyStreamEvent; |
|
|
|
|
import org.apache.commons.net.io.CopyStreamListener; |
|
|
|
|
import org.apache.commons.net.io.FromNetASCIIInputStream; |
|
|
|
|
import org.apache.commons.net.io.ToNetASCIIOutputStream; |
|
|
|
|
import org.apache.commons.net.io.Util; |
|
|
|
|
import aria.apache.commons.net.MalformedServerReplyException; |
|
|
|
|
import aria.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory; |
|
|
|
|
import aria.apache.commons.net.ftp.parser.FTPFileEntryParserFactory; |
|
|
|
|
import aria.apache.commons.net.ftp.parser.MLSxEntryParser; |
|
|
|
|
import aria.apache.commons.net.io.CRLFLineReader; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* FTPClient encapsulates all the functionality necessary to store and |
|
|
|
|
* retrieve files from an FTP server. This class takes care of all |
|
|
|
|
* low level details of interacting with an FTP server and provides |
|
|
|
|
* a convenient higher level interface. As with all classes derived |
|
|
|
|
* from {@link org.apache.commons.net.SocketClient}, |
|
|
|
|
* from {@link SocketClient}, |
|
|
|
|
* you must first connect to the server with |
|
|
|
|
* {@link org.apache.commons.net.SocketClient#connect connect } |
|
|
|
|
* {@link SocketClient#connect connect } |
|
|
|
|
* before doing anything, and finally |
|
|
|
|
* {@link org.apache.commons.net.SocketClient#disconnect disconnect } |
|
|
|
|
* {@link SocketClient#disconnect disconnect } |
|
|
|
|
* after you're completely finished interacting with the server. |
|
|
|
|
* Then you need to check the FTP reply code to see if the connection |
|
|
|
|
* was successful. For example: |
|
|
|
@ -162,14 +167,14 @@ import org.apache.commons.net.io.Util; |
|
|
|
|
* {@link FTPReply#SERVICE_NOT_AVAILABLE FTPReply.SERVICE_NOT_AVAILABLE } |
|
|
|
|
* response to a command. |
|
|
|
|
* When that occurs, the FTP class method encountering that reply will throw |
|
|
|
|
* an {@link org.apache.commons.net.ftp.FTPConnectionClosedException} |
|
|
|
|
* an {@link FTPConnectionClosedException} |
|
|
|
|
* . |
|
|
|
|
* <code>FTPConnectionClosedException</code> |
|
|
|
|
* is a subclass of <code> IOException </code> and therefore need not be |
|
|
|
|
* caught separately, but if you are going to catch it separately, its |
|
|
|
|
* catch block must appear before the more general <code> IOException </code> |
|
|
|
|
* catch block. When you encounter an |
|
|
|
|
* {@link org.apache.commons.net.ftp.FTPConnectionClosedException} |
|
|
|
|
* {@link FTPConnectionClosedException} |
|
|
|
|
* , you must disconnect the connection with |
|
|
|
|
* {@link #disconnect disconnect() } to properly clean up the |
|
|
|
|
* system resources used by FTPClient. Before disconnecting, you may check the |
|
|
|
@ -184,7 +189,7 @@ import org.apache.commons.net.io.Util; |
|
|
|
|
* Rather than list it separately for each method, we mention here that |
|
|
|
|
* every method communicating with the server and throwing an IOException |
|
|
|
|
* can also throw a |
|
|
|
|
* {@link org.apache.commons.net.MalformedServerReplyException} |
|
|
|
|
* {@link MalformedServerReplyException} |
|
|
|
|
* , which is a subclass |
|
|
|
|
* of IOException. A MalformedServerReplyException will be thrown when |
|
|
|
|
* the reply received from the server deviates enough from the protocol |
|
|
|
@ -291,7 +296,7 @@ import org.apache.commons.net.io.Util; |
|
|
|
|
* @see FTPFileEntryParserFactory |
|
|
|
|
* @see DefaultFTPFileEntryParserFactory |
|
|
|
|
* @see FTPClientConfig |
|
|
|
|
* @see org.apache.commons.net.MalformedServerReplyException |
|
|
|
|
* @see MalformedServerReplyException |
|
|
|
|
*/ |
|
|
|
|
public class FTPClient extends FTP implements Configurable { |
|
|
|
|
/** |
|
|
|
@ -320,7 +325,7 @@ public class FTPClient extends FTP implements Configurable { |
|
|
|
|
* For example: |
|
|
|
|
* <pre> |
|
|
|
|
* Plan 9=Unix |
|
|
|
|
* OS410=org.apache.commons.net.ftp.parser.OS400FTPEntryParser |
|
|
|
|
* OS410=OS400FTPEntryParser |
|
|
|
|
* </pre> |
|
|
|
|
* |
|
|
|
|
* @since 3.0 |
|
|
|
@ -713,7 +718,7 @@ public class FTPClient extends FTP implements Configurable { |
|
|
|
|
} else { |
|
|
|
|
output = socket.getOutputStream(); |
|
|
|
|
} |
|
|
|
|
return new org.apache.commons.net.io.SocketOutputStream(socket, output); |
|
|
|
|
return new SocketOutputStream(socket, output); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -1757,7 +1762,7 @@ public class FTPClient extends FTP implements Configurable { |
|
|
|
|
* 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. |
|
|
|
|
* @throws org.apache.commons.net.io.CopyStreamException If an I/O error occurs while actually |
|
|
|
|
* @throws CopyStreamException If an I/O error occurs while actually |
|
|
|
|
* transferring the file. The CopyStreamException allows you to |
|
|
|
|
* determine the number of bytes transferred and the IOException |
|
|
|
|
* causing the error. This exception may be caught either |
|
|
|
@ -1874,7 +1879,7 @@ public class FTPClient extends FTP implements Configurable { |
|
|
|
|
} else { |
|
|
|
|
input = socket.getInputStream(); |
|
|
|
|
} |
|
|
|
|
return new org.apache.commons.net.io.SocketInputStream(socket, input); |
|
|
|
|
return new SocketInputStream(socket, input); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -1892,7 +1897,7 @@ public class FTPClient extends FTP implements Configurable { |
|
|
|
|
* 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. |
|
|
|
|
* @throws org.apache.commons.net.io.CopyStreamException If an I/O error occurs while actually |
|
|
|
|
* @throws CopyStreamException If an I/O error occurs while actually |
|
|
|
|
* transferring the file. The CopyStreamException allows you to |
|
|
|
|
* determine the number of bytes transferred and the IOException |
|
|
|
|
* causing the error. This exception may be caught either |
|
|
|
@ -1965,7 +1970,7 @@ public class FTPClient extends FTP implements Configurable { |
|
|
|
|
* 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. |
|
|
|
|
* @throws org.apache.commons.net.io.CopyStreamException If an I/O error occurs while actually |
|
|
|
|
* @throws CopyStreamException If an I/O error occurs while actually |
|
|
|
|
* transferring the file. The CopyStreamException allows you to |
|
|
|
|
* determine the number of bytes transferred and the IOException |
|
|
|
|
* causing the error. This exception may be caught either |
|
|
|
@ -2026,7 +2031,7 @@ public class FTPClient extends FTP implements Configurable { |
|
|
|
|
* 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. |
|
|
|
|
* @throws org.apache.commons.net.io.CopyStreamException If an I/O error occurs while actually |
|
|
|
|
* @throws CopyStreamException If an I/O error occurs while actually |
|
|
|
|
* transferring the file. The CopyStreamException allows you to |
|
|
|
|
* determine the number of bytes transferred and the IOException |
|
|
|
|
* causing the error. This exception may be caught either |
|
|
|
@ -2087,7 +2092,7 @@ public class FTPClient extends FTP implements Configurable { |
|
|
|
|
* 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. |
|
|
|
|
* @throws org.apache.commons.net.io.CopyStreamException If an I/O error occurs while actually |
|
|
|
|
* @throws CopyStreamException If an I/O error occurs while actually |
|
|
|
|
* transferring the file. The CopyStreamException allows you to |
|
|
|
|
* determine the number of bytes transferred and the IOException |
|
|
|
|
* causing the error. This exception may be caught either |
|
|
|
@ -2826,7 +2831,7 @@ public class FTPClient extends FTP implements Configurable { |
|
|
|
|
* @throws IOException If an I/O error occurs while either sending a |
|
|
|
|
* command to the server or receiving a reply |
|
|
|
|
* from the server. |
|
|
|
|
* @throws org.apache.commons.net.ftp.parser.ParserInitializationException Thrown if the |
|
|
|
|
* @throws ParserInitializationException Thrown if the |
|
|
|
|
* parserKey |
|
|
|
|
* parameter cannot be |
|
|
|
|
* resolved by the selected parser factory. |
|
|
|
@ -2834,13 +2839,13 @@ public class FTPClient extends FTP implements Configurable { |
|
|
|
|
* happen when parserKey is neither |
|
|
|
|
* the fully qualified class name of a class
|
|
|
|
|
* implementing the interface
|
|
|
|
|
* org.apache.commons.net.ftp.FTPFileEntryParser |
|
|
|
|
* FTPFileEntryParser |
|
|
|
|
* nor a string containing one of the recognized keys |
|
|
|
|
* mapping to such a parser or if class loader |
|
|
|
|
* security issues prevent its being loaded. |
|
|
|
|
* @see DefaultFTPFileEntryParserFactory |
|
|
|
|
* @see FTPFileEntryParserFactory |
|
|
|
|
* @see org.apache.commons.net.ftp.FTPFileEntryParser |
|
|
|
|
* @see FTPFileEntryParser |
|
|
|
|
*/ |
|
|
|
|
public FTPFile[] listFiles(String pathname) throws IOException { |
|
|
|
|
FTPListParseEngine engine = initiateListParsing((String) null, pathname); |
|
|
|
@ -2875,7 +2880,7 @@ public class FTPClient extends FTP implements Configurable { |
|
|
|
|
* @throws IOException If an I/O error occurs while either sending a |
|
|
|
|
* command to the server or receiving a reply |
|
|
|
|
* from the server. |
|
|
|
|
* @throws org.apache.commons.net.ftp.parser.ParserInitializationException Thrown if the |
|
|
|
|
* @throws ParserInitializationException Thrown if the |
|
|
|
|
* parserKey |
|
|
|
|
* parameter cannot be |
|
|
|
|
* resolved by the selected parser factory. |
|
|
|
@ -2883,13 +2888,13 @@ public class FTPClient extends FTP implements Configurable { |
|
|
|
|
* happen when parserKey is neither |
|
|
|
|
* the fully qualified class name of a class
|
|
|
|
|
* implementing the interface
|
|
|
|
|
* org.apache.commons.net.ftp.FTPFileEntryParser |
|
|
|
|
* FTPFileEntryParser |
|
|
|
|
* nor a string containing one of the recognized keys |
|
|
|
|
* mapping to such a parser or if class loader |
|
|
|
|
* security issues prevent its being loaded. |
|
|
|
|
* @see DefaultFTPFileEntryParserFactory |
|
|
|
|
* @see FTPFileEntryParserFactory |
|
|
|
|
* @see org.apache.commons.net.ftp.FTPFileEntryParser |
|
|
|
|
* @see FTPFileEntryParser |
|
|
|
|
*/ |
|
|
|
|
public FTPFile[] listFiles() throws IOException { |
|
|
|
|
return listFiles((String) null); |
|
|
|
@ -2934,7 +2939,7 @@ public class FTPClient extends FTP implements Configurable { |
|
|
|
|
* @throws IOException If an I/O error occurs while either sending a |
|
|
|
|
* command to the server or receiving a reply |
|
|
|
|
* from the server. |
|
|
|
|
* @throws org.apache.commons.net.ftp.parser.ParserInitializationException Thrown if the |
|
|
|
|
* @throws ParserInitializationException Thrown if the |
|
|
|
|
* parserKey |
|
|
|
|
* parameter cannot be |
|
|
|
|
* resolved by the selected parser factory. |
|
|
|
@ -2942,13 +2947,13 @@ public class FTPClient extends FTP implements Configurable { |
|
|
|
|
* happen when parserKey is neither |
|
|
|
|
* the fully qualified class name of a class
|
|
|
|
|
* implementing the interface
|
|
|
|
|
* org.apache.commons.net.ftp.FTPFileEntryParser |
|
|
|
|
* FTPFileEntryParser |
|
|
|
|
* nor a string containing one of the recognized keys |
|
|
|
|
* mapping to such a parser or if class loader |
|
|
|
|
* security issues prevent its being loaded. |
|
|
|
|
* @see DefaultFTPFileEntryParserFactory |
|
|
|
|
* @see FTPFileEntryParserFactory |
|
|
|
|
* @see org.apache.commons.net.ftp.FTPFileEntryParser |
|
|
|
|
* @see FTPFileEntryParser |
|
|
|
|
* @since 3.0 |
|
|
|
|
*/ |
|
|
|
|
public FTPFile[] listDirectories() throws IOException { |
|
|
|
@ -2980,7 +2985,7 @@ public class FTPClient extends FTP implements Configurable { |
|
|
|
|
* @throws IOException If an I/O error occurs while either sending a |
|
|
|
|
* command to the server or receiving a reply |
|
|
|
|
* from the server. |
|
|
|
|
* @throws org.apache.commons.net.ftp.parser.ParserInitializationException Thrown if the |
|
|
|
|
* @throws ParserInitializationException Thrown if the |
|
|
|
|
* parserKey |
|
|
|
|
* parameter cannot be |
|
|
|
|
* resolved by the selected parser factory. |
|
|
|
@ -2988,13 +2993,13 @@ public class FTPClient extends FTP implements Configurable { |
|
|
|
|
* happen when parserKey is neither |
|
|
|
|
* the fully qualified class name of a class
|
|
|
|
|
* implementing the interface
|
|
|
|
|
* org.apache.commons.net.ftp.FTPFileEntryParser |
|
|
|
|
* FTPFileEntryParser |
|
|
|
|
* nor a string containing one of the recognized keys |
|
|
|
|
* mapping to such a parser or if class loader |
|
|
|
|
* security issues prevent its being loaded. |
|
|
|
|
* @see DefaultFTPFileEntryParserFactory |
|
|
|
|
* @see FTPFileEntryParserFactory |
|
|
|
|
* @see org.apache.commons.net.ftp.FTPFileEntryParser |
|
|
|
|
* @see FTPFileEntryParser |
|
|
|
|
* @since 3.0 |
|
|
|
|
*/ |
|
|
|
|
public FTPFile[] listDirectories(String parent) throws IOException { |
|
|
|
@ -3027,7 +3032,7 @@ public class FTPClient extends FTP implements Configurable { |
|
|
|
|
* as an IOException or independently as itself. |
|
|
|
|
* @throws IOException If an I/O error occurs while either sending a |
|
|
|
|
* command to the server or receiving a reply from the server. |
|
|
|
|
* @throws org.apache.commons.net.ftp.parser.ParserInitializationException Thrown if the |
|
|
|
|
* @throws ParserInitializationException Thrown if the |
|
|
|
|
* autodetect mechanism cannot |
|
|
|
|
* resolve the type of system we are connected with. |
|
|
|
|
* @see FTPListParseEngine |
|
|
|
@ -3079,7 +3084,7 @@ public class FTPClient extends FTP implements Configurable { |
|
|
|
|
* as an IOException or independently as itself. |
|
|
|
|
* @throws IOException If an I/O error occurs while either sending a |
|
|
|
|
* command to the server or receiving a reply from the server. |
|
|
|
|
* @throws org.apache.commons.net.ftp.parser.ParserInitializationException Thrown if the |
|
|
|
|
* @throws ParserInitializationException Thrown if the |
|
|
|
|
* autodetect mechanism cannot |
|
|
|
|
* resolve the type of system we are connected with. |
|
|
|
|
* @see FTPListParseEngine |
|
|
|
@ -3127,7 +3132,7 @@ public class FTPClient extends FTP implements Configurable { |
|
|
|
|
* as an IOException or independently as itself. |
|
|
|
|
* @throws IOException If an I/O error occurs while either sending a |
|
|
|
|
* command to the server or receiving a reply from the server. |
|
|
|
|
* @throws org.apache.commons.net.ftp.parser.ParserInitializationException Thrown if the |
|
|
|
|
* @throws ParserInitializationException Thrown if the |
|
|
|
|
* parserKey |
|
|
|
|
* parameter cannot be |
|
|
|
|
* resolved by the selected parser factory. |
|
|
|
@ -3135,7 +3140,7 @@ public class FTPClient extends FTP implements Configurable { |
|
|
|
|
* happen when parserKey is neither |
|
|
|
|
* the fully qualified class name of a class
|
|
|
|
|
* implementing the interface
|
|
|
|
|
* org.apache.commons.net.ftp.FTPFileEntryParser |
|
|
|
|
* FTPFileEntryParser |
|
|
|
|
* nor a string containing one of the recognized keys |
|
|
|
|
* mapping to such a parser or if class loader |
|
|
|
|
* security issues prevent its being loaded. |