📄 ftpclient.java
字号:
final public static byte[] FTP_LINE_SEPARATOR = {CARRIAGE_RETURN, LINE_FEED};
/**
* Marker in reply for STOU reply with filename
*/
final private static String STOU_FILENAME_MARKER = "FILE:";
/**
* Store command
*/
final private static String STORE_CMD = "STOR ";
/**
* Store unique command
*/
final private static String STORE_UNIQ_CMD = "STOU ";
/**
* MFMT return string keyword
*/
final private static String MODTIME_STR = "modtime";
/**
* Default locales
*/
public static Locale[] DEFAULT_LISTING_LOCALES;
/**
* Logging object
*/
private static Logger log = Logger.getLogger("FTPClient");
/**
* Format to interpret MTDM timestamp
*/
private SimpleDateFormat tsFormat =
new SimpleDateFormat("yyyyMMddHHmmss");
/**
* Socket responsible for controlling
* the connection
*/
protected FTPControlSocket control = null;
/**
* Socket responsible for transferring
* the data
*/
protected FTPDataSocket data = null;
/**
* Socket timeout for both data and control. In
* milliseconds
*/
protected int timeout = DEFAULT_TIMEOUT;
/**
* Interval in seconds in between server wakeups. O is
* not enabled
*/
protected int serverWakeupInterval = 0;
/**
* Address of the remote server.
*/
protected InetAddress remoteAddr;
/**
* Name/IP of remote host
*/
protected String remoteHost;
/**
* Id of instance
*/
protected String id;
/**
* Master id
*/
private static int masterId = 0;
/**
* Control port number.
*/
protected int controlPort = FTPControlSocket.CONTROL_PORT;
/**
* If true, uses the original host IP if an internal IP address
* is returned by the server in PASV mode
*/
private boolean autoPassiveIPSubstitution = false;
/**
* IP address to force to use in active mode
*/
private String activeIP = null;
/**
* Encoding used on control socket
*/
protected String controlEncoding = DEFAULT_ENCODING;
/**
* Use strict return codes if true
*/
private boolean strictReturnCodes = false;
/**
* Matcher for directory empty
*/
protected DirectoryEmptyStrings dirEmptyStrings = new DirectoryEmptyStrings();
/**
* Matcher for transfer complete
*/
protected TransferCompleteStrings transferCompleteStrings = new TransferCompleteStrings();
/**
* Matcher for permission denied
*/
protected FileNotFoundStrings fileNotFoundStrings = new FileNotFoundStrings();
/**
* Can be used to cancel a transfer
*/
private boolean cancelTransfer = false;
/**
* If true, a file transfer is being resumed
*/
private boolean resume = false;
/**
* MDTM supported flag
*/
private boolean mdtmSupported = true;
/**
* SIZE supported flag
*/
private boolean sizeSupported = true;
/**
* Resume byte marker point
*/
private long resumeMarker = 0;
/**
* Delete partial files on transfer failure?
*/
private boolean deleteOnFailure = true;
/**
* If true, filetypes are autodetected and transfer mode changed to binary/ASCII as
* required
*/
protected boolean detectTransferMode = false;
/**
* Lowest port in active mode port range
*/
private int lowPort = -1;
/**
* Highest port in active mode port range
*/
private int highPort = -1;
/**
* Command sent to server for storing a file
*/
private String storeCommand = STORE_CMD;
/**
* Bytes transferred in between monitor callbacks
*/
protected long monitorInterval = DEFAULT_MONITOR_INTERVAL;
/**
* Size of transfer buffers
*/
protected int transferBufferSize = DEFAULT_BUFFER_SIZE;
/**
* Count of downloaded files
*/
private int downloadCount = 0;
/**
* Count of uploaded files
*/
private int uploadCount = 0;
/**
* Count of deleted files
*/
private int deleteCount = 0;
/**
* Listen to all interfaces in active mode
*/
private boolean listenOnAllInterfaces = true;
/**
* Parses LIST output
*/
private FTPFileFactory fileFactory = null;
/**
* Locales for date parsing
*/
private Locale[] listingLocales;
/**
* Parses the MLSD and MLST formats
*/
private MLSXEntryParser mlsxParser = new MLSXEntryParser();
/**
* Progress monitor
*/
protected FTPProgressMonitor monitor = null;
/**
* Message listener
*/
protected FTPMessageListener messageListener = null;
/**
* File transfer listener
*/
protected FTPProgressMonitorEx monitorEx = null;
/**
* Record of the transfer type - make the default ASCII
*/
protected FTPTransferType transferType = FTPTransferType.ASCII;
/**
* Record of the connect mode - make the default PASV (as this was
* the original mode supported)
*/
private FTPConnectMode connectMode = FTPConnectMode.PASV;
/**
* Holds the last valid reply from the server on the control socket
*/
protected FTPReply lastValidReply;
/**
* Holds the last reply from the server on the control socket
*/
protected FTPReply lastReply;
/**
* set default listing locales.
*/
static {
DEFAULT_LISTING_LOCALES = new Locale[2];
DEFAULT_LISTING_LOCALES[0] = Locale.ENGLISH;
DEFAULT_LISTING_LOCALES[1] = Locale.getDefault();
}
/**
* Instance initializer. Sets formatter to GMT.
*/
{
tsFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
listingLocales = DEFAULT_LISTING_LOCALES;
id = Integer.toString(++masterId);
}
/**
* Get the version of edtFTPj
*
* @return int array of {major,middle,minor} version numbers
*/
public static int[] getVersion() {
return VersionDetails.getVersion();
}
/**
* Get the build timestamp
*
* @return d-MMM-yyyy HH:mm:ss z build timestamp
*/
public static String getBuildTimestamp() {
return VersionDetails.getBuildTimestamp();
}
/**
* Constructor. Creates the control
* socket
*
* @param remoteHost the remote hostname
* @deprecated use setter methods to set properties
*/
public FTPClient(String remoteHost)
throws IOException, FTPException {
this(remoteHost, FTPControlSocket.CONTROL_PORT, 0);
}
/**
* Constructor. Creates the control
* socket
*
* @param remoteHost the remote hostname
* @param controlPort port for control stream (-1 for default port)
* @deprecated use setter methods to set properties
*/
public FTPClient(String remoteHost, int controlPort)
throws IOException, FTPException {
this(remoteHost, controlPort, 0);
}
/**
* Constructor. Creates the control
* socket
*
* @param remoteHost the remote hostname
* @param controlPort port for control stream (use -1 for the default port)
* @param timeout the length of the timeout, in milliseconds
* (pass in 0 for no timeout)
* @deprecated use setter methods to set properties
*/
public FTPClient(String remoteHost, int controlPort, int timeout)
throws IOException, FTPException {
this(InetAddress.getByName(remoteHost), controlPort, timeout);
}
/**
* Constructor. Creates the control
* socket
*
* @param remoteHost the remote hostname
* @param controlPort port for control stream (use -1 for the default port)
* @param timeout the length of the timeout, in milliseconds
* (pass in 0 for no timeout)
* @param encoding character encoding used for data
* @deprecated use setter methods to set properties
*/
public FTPClient(String remoteHost, int controlPort, int timeout, String encoding)
throws IOException, FTPException {
this(InetAddress.getByName(remoteHost), controlPort, timeout, encoding);
}
/**
* Constructor. Creates the control
* socket
*
* @param remoteAddr the address of the
* remote host
* @deprecated use setter methods to set properties
*/
public FTPClient(InetAddress remoteAddr)
throws IOException, FTPException {
this(remoteAddr, FTPControlSocket.CONTROL_PORT, 0);
}
/**
* Constructor. Creates the control
* socket. Allows setting of control port (normally
* set by default to 21).
*
* @param remoteAddr the address of the
* remote host
* @param controlPort port for control stream
* @deprecated use setter methods to set properties
*/
public FTPClient(InetAddress remoteAddr, int controlPort)
throws IOException, FTPException {
this(remoteAddr, controlPort, 0);
}
/**
* Constructor. Creates the control
* socket. Allows setting of control port (normally
* set by default to 21).
*
* @param remoteAddr the address of the
* remote host
* @param controlPort port for control stream (-1 for default port)
* @param timeout the length of the timeout, in milliseconds
* (pass in 0 for no timeout)
* @deprecated use setter methods to set properties
*/
public FTPClient(InetAddress remoteAddr, int controlPort, int timeout)
throws IOException, FTPException {
if (controlPort < 0)
controlPort = FTPControlSocket.CONTROL_PORT;
initialize(new FTPControlSocket(remoteAddr, controlPort, timeout, DEFAULT_ENCODING, null));
}
/**
* Constructor. Creates the control
* socket. Allows setting of control port (normally
* set by default to 21).
*
* @param remoteAddr the address of the
* remote host
* @param controlPort port for control stream (-1 for default port)
* @param timeout the length of the timeout, in milliseconds
* (pass in 0 for no timeout)
* @param encoding character encoding used for data
* @deprecated use setter methods to set properties
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -