📄 ftpclient.java
字号:
/**
* Returns the control-port being connected to on the remote server.
* @return Returns the port being connected to on the remote server.
* @deprecated Use {@link com.enterprisedt.net.ftp.FTPClientInterface#getRemotePort()} instead.
*/
public int getControlPort() {
return controlPort;
}
/**
* Set the control to connect to on the remote server. Can only do this if
* not already connected.
*
* @param controlPort The port to use.
* @throws FTPException Thrown if the client is already connected to the server.
* @deprecated Use {@link com.enterprisedt.net.ftp.FTPClientInterface#setRemotePort(int)} instead.
*/
public void setControlPort(int controlPort) throws FTPException {
checkConnection(false);
this.controlPort = controlPort;
}
/**
* @return Returns the remoteAddr.
*/
public InetAddress getRemoteAddr() {
return remoteAddr;
}
/**
* Set the remote address
*
* @param remoteAddr The remoteAddr to set.
* @throws FTPException
*/
public void setRemoteAddr(InetAddress remoteAddr) throws FTPException {
checkConnection(false);
this.remoteAddr = remoteAddr;
this.remoteHost = remoteAddr.getHostName();
}
/*
* (non-Javadoc)
* @see com.enterprisedt.net.ftp.FTPClientInterface#getRemoteHost()
*/
public String getRemoteHost() {
return remoteHost;
}
/*
* (non-Javadoc)
* @see com.enterprisedt.net.ftp.FTPClientInterface#setRemoteHost(java.lang.String)
*/
public void setRemoteHost(String remoteHost) throws IOException, FTPException {
checkConnection(false);
this.remoteHost = remoteHost;
this.remoteAddr = InetAddress.getByName(remoteHost);
}
/**
* Is automatic substitution of the remote host IP set to
* be on for passive mode connections?
*
* @return true if set on, false otherwise
*/
public boolean isAutoPassiveIPSubstitution() {
return autoPassiveIPSubstitution;
}
/**
* Set automatic substitution of the remote host IP on if
* in passive mode
*
* @param autoPassiveIPSubstitution true if set to on, false otherwise
*/
public void setAutoPassiveIPSubstitution(boolean autoPassiveIPSubstitution) {
this.autoPassiveIPSubstitution = autoPassiveIPSubstitution;
if (control != null)
control.setAutoPassiveIPSubstitution(autoPassiveIPSubstitution);
}
/**
* Get server wakeup interval in seconds. A value of 0
* means it is disabled (the default).
*
* @return interval in seconds
*/
public int getServerWakeupInterval() {
return serverWakeupInterval;
}
/**
* Set server wakeup interval in seconds. A value of 0
* means it is disabled (the default). This may hang or confuse
* the FTP server - use with caution.
*
* @param interval interval in seconds
*/
public void setServerWakeupInterval(int interval) {
this.serverWakeupInterval = interval;
}
/**
* Get the encoding used for the control connection
*
* @return Returns the current controlEncoding.
*/
public String getControlEncoding() {
return controlEncoding;
}
/**
* Set the control socket's encoding. Can only do this if
* not connected
*
* @param controlEncoding The controlEncoding to set, which is the name of a Charset
* @see java.nio.charset.Charset
* @throws FTPException
*/
public void setControlEncoding(String controlEncoding) throws FTPException {
checkConnection(false);
this.controlEncoding = controlEncoding;
}
/**
* @return Returns the messageListener.
*/
public FTPMessageListener getMessageListener() {
return messageListener;
}
/**
* Set a listener that handles all FTP messages
*
* @param listener message listener
*/
public void setMessageListener(FTPMessageListener listener) {
this.messageListener = listener;
if (control != null)
control.setMessageListener(listener);
}
/**
* Get reference to the transfer listener
*
* @return FTPProgressMonitorEx
*/
public FTPProgressMonitorEx getProgressMonitorEx() {
return monitorEx;
}
/**
* Set reference to the transfer listener
*
* @param monitorEx transfer listener
*/
public void setProgressMonitorEx(FTPProgressMonitorEx monitorEx) {
this.monitorEx = monitorEx;
}
/**
* Set the connect mode
*
* @param mode ACTIVE or PASV mode
*/
public void setConnectMode(FTPConnectMode mode) {
connectMode = mode;
}
/**
* @return Returns the connectMode.
*/
public FTPConnectMode getConnectMode() {
return connectMode;
}
/*
* (non-Javadoc)
* @see com.enterprisedt.net.ftp.FTPClientInterface#setProgressMonitor(com.enterprisedt.net.ftp.FTPProgressMonitor, long)
*/
public void setProgressMonitor(FTPProgressMonitor monitor, long interval) {
this.monitor = monitor;
this.monitorInterval = interval;
}
/*
* (non-Javadoc)
* @see com.enterprisedt.net.ftp.FTPClientInterface#setProgressMonitor(com.enterprisedt.net.ftp.FTPProgressMonitor)
*/
public void setProgressMonitor(FTPProgressMonitor monitor) {
this.monitor = monitor;
}
/**
* Get the reference to the progress monitor
*
* @return progress monitor
*/
public FTPProgressMonitor getProgressMonitor() {
return monitor;
}
/*
* (non-Javadoc)
* @see com.enterprisedt.net.ftp.FTPClientInterface#getMonitorInterval()
*/
public long getMonitorInterval() {
return monitorInterval;
}
/**
* Set the number of bytes transferred between each callback on the
* progress monitor
*
* param interval bytes to be transferred before a callback
*/
public void setMonitorInterval(long interval) {
this.monitorInterval = interval;
}
/**
* Set the size of the buffers used in writing to and reading from
* the data sockets
*
* @param size new size of buffer in bytes
*/
public void setTransferBufferSize(int size) {
transferBufferSize = size;
}
/**
* Get the size of the buffers used in writing to and reading from
* the data sockets
*
* @return transfer buffer size
*/
public int getTransferBufferSize() {
return transferBufferSize;
}
/*
* (non-Javadoc)
* @see com.enterprisedt.net.ftp.FTPClientInterface#cancelTransfer()
*/
public void cancelTransfer() {
cancelTransfer = true;
log.warn("cancelTransfer() called");
}
/**
* Has the current transfer been cancelled?
*
* @return true if cancel, false otherwise
*/
public boolean isTransferCancelled() {
return cancelTransfer;
}
/**
* If true, delete partially written files when exceptions are thrown
* during a download
*
* @return true if delete local file on error
*/
public boolean isDeleteOnFailure() {
return deleteOnFailure;
}
/**
* Switch on or off the automatic deletion of partially written files
* that are left when an exception is thrown during a download
*
* @param deleteOnFailure true if delete when a failure occurs
*/
public void setDeleteOnFailure(boolean deleteOnFailure) {
this.deleteOnFailure = deleteOnFailure;
}
/**
* We can force PORT to send a fixed IP address, which can be useful with certain
* NAT configurations. Must be connected to the remote host to call this method.
*
* @param IPAddress IP address to force, in 192.168.1.0 form
* @deprecated
*/
public void setPORTIP(String IPAddress)
throws FTPException {
setActiveIPAddress(IPAddress);
}
/**
* We can force PORT to send a fixed IP address, which can be useful with certain
* NAT configurations. Must be connected to the remote host to call this method.
*
* @param activeIP IP address to force, in 192.168.1.0 form or in IPV6 form, e.g.
* 1080::8:800:200C:417A
*/
public void setActiveIPAddress(String activeIP)
throws FTPException {
this.activeIP = activeIP;
if (control != null)
control.setActivePortIPAddress(activeIP);
}
/**
* Get the active IP address that is set.
*
* @return active IP address or null if not set
*/
public String getActiveIPAddress() {
return activeIP;
}
/**
* Force a certain range of ports to be used in active mode. This is
* generally so that a port range can be configured in a firewall. Note
* that if lowest == highest, a single port will be used. This works well
* for uploads, but downloads generally require multiple ports, as most
* servers fail to create a connection repeatedly for the same port.
*
* @param lowest Lower limit of range.
* @param highest Upper limit of range.
*/
public void setActivePortRange(int lowest, int highest)
throws FTPException {
this.lowPort = lowest;
this.highPort = highest;
if (lowest < 0 || lowest > highest || highest > MAX_PORT)
throw new FTPException("Invalid port range specified");
if (control != null)
control.setActivePortRange(lowest, highest);
log.debug("setActivePortRange(" + lowest + "," + highest + ")");
}
/**
* Get the lower limit of the port range for active mode.
*
* @return lower limit, or -1 if not set
*/
public int getActiveLowPort() {
return lowPort;
}
/**
* Get the upper limit of the port range for active mode.
*
* @return upper limit, or -1 if not set
*/
public int getActiveHighPort() {
return highPort;
}
/**
* Login into an account on the FTP server. This
* call completes the entire login process. Note that
* connect() must be called first.
*
* @param user user name
* @param password user's password
*/
public void login(String user, String password)
throws IOException, FTPException {
checkConnection(true);
user(user);
if (lastValidReply.getReplyCode().equals("230"))
return;
else {
password(password);
}
}
/**
* Login into an account on the FTP server. This call completes the
* entire login process. This method permits additional account information
* to be supplied. FTP servers can use combinations of these parameters in
* many different ways, e.g. to pass in proxy details via this method, some
* servers use the "user" as 'ftpUser + "@" + ftpHost + " " + ftpProxyUser',
* the "password" as the FTP user's password, and the accountInfo as the proxy
* password. Note that connect() must be called first.
*
* @param user user name
* @param password user's password
* @param accountInfo account info string
*/
public void login(String user, String password, String accountInfo)
throws IOException, FTPException {
checkConnection(true);
user(user);
if (lastValidReply.getReplyCode().equals("230")) // no pwd
return;
else {
password(password);
if (lastValidReply.getReplyCode().equals("332")) // requires acct info
account(accountInfo);
}
}
/**
* Supply the user name to log into an account
* on the FTP server. Must be followed by the
* password() method - but we allow for no password.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -