Package com.enterprisedt.net.ftp
Class FTPControlSocket
java.lang.Object
com.enterprisedt.net.ftp.FTPControlSocket
Supports client-side FTP operations
- Version:
- $Revision$
- Author:
- Bruce Blackshaw
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanIf true, uses the original host IP if an internal IP address is returned by the server in PASV modestatic final intThe default and standard control port number for FTPprotected StreamSocketThe underlying socket.static final StringRevision control idprotected DataChannelCallbackPasv callback methodprotected static final StringEnd of PASV reply in IPv6protected static final StringStart of PASV reply in IPv6protected StringIP address we force PORT to send - useful with certain NAT configurationsprotected booleanListen to all interfaces in active modestatic final intMaximum number of auto retries in active modeprotected ReaderThe reader that reads control data from the control socketprotected InetAddressThe remote address to connect toprotected WriterThe write that writes to the control socket -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedFTPControlSocket(InetAddress remoteAddr, int controlPort, int timeout, String encoding, FTPMessageListener messageListener) Constructor.protectedFTPControlSocket(InetAddress remoteAddr, StreamSocket controlSock, int timeout, String encoding, FTPMessageListener messageListener) Constructs a newFTPControlSocketusing the givenSocketobject. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the socketprotected com.enterprisedt.net.ftp.internal.FTPDataSocketRequest a data socket be created on the server, connect to it and return our connected socket.protected voidInitialize the reader/writer streams for this connection.protected booleanisIPV6(InetAddress host) Is this an IPV6 InetAddress?booleanIs this socket in secure mode?voidlogout()Quit this FTP session and clean up.protected com.enterprisedt.net.ftp.internal.FTPDataSocketnewActiveDataSocket(int port) Constructs a newFTPDataSocketobject (server mode) which will listen on the given port number.protected com.enterprisedt.net.ftp.internal.FTPDataSocketnewPassiveDataSocket(String remoteHost, int port) Constructs a newFTPDataSocketobject (client mode) and connect to the given remote host and port number.sendCommand(String command) Send a command to the FTP server and return the server's reply as a structured reply objectvoidsetActivePortRange(int lowest, int highest) Set the port number range for active modeprotected voidsetAutoPassiveIPSubstitution(boolean autoPassiveIPSubstitution) Set automatic substitution of the remote host IP on if in passive modeprotected voidsetDataPort(InetAddress host, int portNo) Sets the data port on the server, that is, sends a PORT command.protected byte[]toByteArray(int value) Convert a short into a byte arrayprotected booleanvalidateReply(FTPReply reply, String expectedReplyCode) Validate the response the host has supplied against the expected reply.validateReply(FTPReply reply, String[] expectedReplyCodes) Validate the response the host has supplied against the expected reply.validateReply(String reply, String[] expectedReplyCodes) Validate the response the host has supplied against the expected reply.
-
Field Details
-
cvsId
Revision control id- See Also:
-
MAX_ACTIVE_RETRY
public static final int MAX_ACTIVE_RETRYMaximum number of auto retries in active mode- See Also:
-
CONTROL_PORT
public static final int CONTROL_PORTThe default and standard control port number for FTP- See Also:
-
EPSV_START
Start of PASV reply in IPv6- See Also:
-
EPSV_END
End of PASV reply in IPv6- See Also:
-
listenOnAllInterfaces
protected boolean listenOnAllInterfacesListen to all interfaces in active mode -
controlSock
The underlying socket. -
writer
The write that writes to the control socket -
reader
The reader that reads control data from the control socket -
forcedActiveIP
IP address we force PORT to send - useful with certain NAT configurations -
remoteAddr
The remote address to connect to -
autoPassiveIPSubstitution
protected boolean autoPassiveIPSubstitutionIf true, uses the original host IP if an internal IP address is returned by the server in PASV mode -
dataChannelCallback
Pasv callback method
-
-
Constructor Details
-
FTPControlSocket
protected FTPControlSocket(InetAddress remoteAddr, int controlPort, int timeout, String encoding, FTPMessageListener messageListener) throws IOException, FTPException Constructor. Performs TCP connection and sets up reader/writer. Allows different control port to be used- Parameters:
remoteAddr- Remote inet addresscontrolPort- port for control streamtimeout- the length of the timeout, in millisecondsencoding- character encoding used for datamessageListener- listens for messages- Throws:
IOExceptionFTPException
-
FTPControlSocket
protected FTPControlSocket(InetAddress remoteAddr, StreamSocket controlSock, int timeout, String encoding, FTPMessageListener messageListener) throws IOException, FTPException Constructs a newFTPControlSocketusing the givenSocketobject.- Parameters:
remoteAddr- the remote addresscontrolSock- Socket to be used.timeout- Timeout to be used.encoding- character encoding used for datamessageListener- listens for messages- Throws:
IOException- Thrown if no connection response could be read from the server.FTPException- Thrown if the incorrect connection response was sent by the server.
-
-
Method Details
-
setAutoPassiveIPSubstitution
protected void setAutoPassiveIPSubstitution(boolean autoPassiveIPSubstitution) Set automatic substitution of the remote host IP on if in passive mode- Parameters:
autoPassiveIPSubstitution- true if set to on, false otherwise
-
initStreams
Initialize the reader/writer streams for this connection.- Throws:
IOException
-
isSecureMode
public boolean isSecureMode()Is this socket in secure mode?- Returns:
- true if secure mode
-
close
Close the socket- Throws:
IOException
-
logout
Quit this FTP session and clean up.- Throws:
IOException
-
toByteArray
protected byte[] toByteArray(int value) Convert a short into a byte array- Parameters:
value- value to convert- Returns:
- a byte array
-
setActivePortRange
public void setActivePortRange(int lowest, int highest) Set the port number range for active mode- Parameters:
lowest- lowest port number in rangehighest- highest port number in range
-
setDataPort
Sets the data port on the server, that is, sends a PORT command.- Parameters:
host- the local host the server will connect toportNo- the port number to connect to- Throws:
IOExceptionFTPException
-
createDataSocketPASV
protected com.enterprisedt.net.ftp.internal.FTPDataSocket createDataSocketPASV() throws IOException, FTPExceptionRequest a data socket be created on the server, connect to it and return our connected socket.- Returns:
- connected data socket
- Throws:
IOExceptionFTPException
-
usingProxy
protected boolean usingProxy() -
newPassiveDataSocket
protected com.enterprisedt.net.ftp.internal.FTPDataSocket newPassiveDataSocket(String remoteHost, int port) throws IOException Constructs a newFTPDataSocketobject (client mode) and connect to the given remote host and port number.- Parameters:
remoteHost- Remote host to connect to.port- Remote port to connect to.- Returns:
- A new
FTPDataSocketobject (client mode) which is connected to the given server. - Throws:
IOException- Thrown if no TCP/IP connection could be made.
-
newActiveDataSocket
protected com.enterprisedt.net.ftp.internal.FTPDataSocket newActiveDataSocket(int port) throws IOException Constructs a newFTPDataSocketobject (server mode) which will listen on the given port number.- Parameters:
port- Remote port to listen on.- Returns:
- A new
FTPDataSocketobject (server mode) which is configured to listen on the given port. - Throws:
IOException- Thrown if an error occurred when creating the socket.
-
sendCommand
Send a command to the FTP server and return the server's reply as a structured reply object- Parameters:
command- command to send- Returns:
- reply to the supplied command
- Throws:
IOExceptionFTPException
-
validateReply
public FTPReply validateReply(String reply, String[] expectedReplyCodes) throws IOException, FTPException Validate the response the host has supplied against the expected reply. If we get an unexpected reply we throw an exception, setting the message to that returned by the FTP server- Parameters:
reply- the entire reply string we receivedexpectedReplyCodes- array of expected replies- Returns:
- an object encapsulating the server's reply
- Throws:
IOExceptionFTPException
-
validateReply
Validate the response the host has supplied against the expected reply. If we get an unexpected reply we throw an exception, setting the message to that returned by the FTP server- Parameters:
reply- reply objectexpectedReplyCodes- array of expected replies- Returns:
- reply object
- Throws:
FTPException
-
validateReply
Validate the response the host has supplied against the expected reply. If we get an unexpected reply we throw an exception, setting the message to that returned by the FTP server- Parameters:
reply- reply objectexpectedReplyCode- expected reply- Returns:
- reply object
- Throws:
FTPException
-
isIPV6
Is this an IPV6 InetAddress?- Parameters:
host- InetAddress to test- Returns:
- true if IPV6, false otherwise
-