it.sauronsoftware.ftp4j
Class FTPConnector

java.lang.Object
  extended by it.sauronsoftware.ftp4j.FTPConnector
Direct Known Subclasses:
DirectConnector, FTPProxyConnector, HTTPTunnelConnector, SOCKS4Connector, SOCKS5Connector

public abstract class FTPConnector
extends java.lang.Object

This abstract class is the base for creating a connector. Connectors are used by the client to establish connections with remote servers.

Author:
Carlo Pelliccia

Field Summary
protected  int closeTimeout
          Timeout in seconds for connection regular closing.
protected  int connectionTimeout
          Timeout in seconds for connection enstablishing.
protected  int readTimeout
          Timeout in seconds for read operations.
 
Constructor Summary
protected FTPConnector()
          Builds the connector.
protected FTPConnector(boolean useSuggestedAddressForDataConnectionsDefValue)
          Builds the connector.
 
Method Summary
 void abortConnectForCommunicationChannel()
          Aborts an ongoing connection attempt for a communication channel.
abstract  java.net.Socket connectForCommunicationChannel(java.lang.String host, int port)
          This methods returns an established connection to a remote host, suitable for a FTP communication channel.
abstract  java.net.Socket connectForDataTransferChannel(java.lang.String host, int port)
          This methods returns an established connection to a remote host, suitable for a FTP data transfer channel.
 void setCloseTimeout(int closeTimeout)
          Sets the timeout for close operations.
 void setConnectionTimeout(int connectionTimeout)
          Sets the timeout for connection operations.
 void setReadTimeout(int readTimeout)
          Sets the timeout for read operations.
 void setUseSuggestedAddressForDataConnections(boolean value)
          This flag determines the behavior of the connector when it has to open a connection toward the server to perform a passive data transfer.
protected  java.net.Socket tcpConnectForCommunicationChannel(java.lang.String host, int port)
          Creates a socket and connects it to the given host for a communication channel.
protected  java.net.Socket tcpConnectForDataTransferChannel(java.lang.String host, int port)
          Creates a socket and connects it to the given host for a data transfer channel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connectionTimeout

protected int connectionTimeout
Timeout in seconds for connection enstablishing.

Since:
1.7

readTimeout

protected int readTimeout
Timeout in seconds for read operations.

Since:
1.7

closeTimeout

protected int closeTimeout
Timeout in seconds for connection regular closing.

Since:
1.7
Constructor Detail

FTPConnector

protected FTPConnector(boolean useSuggestedAddressForDataConnectionsDefValue)
Builds the connector.

Parameters:
useSuggestedAddressForDataConnectionsDefValue - The connector's default value for the useSuggestedAddressForDataConnections flag.
See Also:
setUseSuggestedAddressForDataConnections(boolean)

FTPConnector

protected FTPConnector()
Builds the connector. By calling this constructor, the connector's default value for the useSuggestedAddressForDataConnections flag is false.

Method Detail

setConnectionTimeout

public void setConnectionTimeout(int connectionTimeout)
Sets the timeout for connection operations.

Parameters:
connectionTimeout - The timeout value in seconds.
Since:
1.7

setReadTimeout

public void setReadTimeout(int readTimeout)
Sets the timeout for read operations.

Parameters:
readTimeout - The timeout value in seconds.
Since:
1.7

setCloseTimeout

public void setCloseTimeout(int closeTimeout)
Sets the timeout for close operations.

Parameters:
closeTimeout - The timeout value in seconds.
Since:
1.7

setUseSuggestedAddressForDataConnections

public void setUseSuggestedAddressForDataConnections(boolean value)
This flag determines the behavior of the connector when it has to open a connection toward the server to perform a passive data transfer. If the flag is true, the client connects to the IP address returned as a reply of the PASV command. If the flag is false, the client ignores the IP address suggested by the server, and it connects to the same host used for the communication connection (the same host supplied in the FTPClient.connect(String) and FTPClient.connect(String, int) methods). In this case, the response to the PASV command is used only to determinate the port for the connection. The default value for this flag (the one used if you never the method is never called) depends on:

Parameters:
value - The value for the flag.

tcpConnectForCommunicationChannel

protected java.net.Socket tcpConnectForCommunicationChannel(java.lang.String host,
                                                            int port)
                                                     throws java.io.IOException
Creates a socket and connects it to the given host for a communication channel. Socket timeouts are automatically set according to the values of connectionTimeout, readTimeout and closeTimeout. If you are extending FTPConnector, consider using this method to establish your socket connection for the communication channel, instead of creating Socket objects, since it is already aware of the timeout values possibly given by the caller. Moreover the caller can abort connection calling FTPClient.abortCurrentConnectionAttempt().

Parameters:
host - The host for the connection.
port - The port for the connection.
Returns:
The connected socket.
Throws:
java.io.IOException - If connection fails.
Since:
1.7

tcpConnectForDataTransferChannel

protected java.net.Socket tcpConnectForDataTransferChannel(java.lang.String host,
                                                           int port)
                                                    throws java.io.IOException
Creates a socket and connects it to the given host for a data transfer channel. Socket timeouts are automatically set according to the values of connectionTimeout, readTimeout and closeTimeout. If you are extending FTPConnector, consider using this method to establish your socket connection for the communication channel, instead of creating Socket objects, since it is already aware of the timeout values possibly given by the caller.

Parameters:
host - The host for the connection.
port - The port for the connection.
Returns:
The connected socket.
Throws:
java.io.IOException - If connection fails.
Since:
1.7

abortConnectForCommunicationChannel

public void abortConnectForCommunicationChannel()
Aborts an ongoing connection attempt for a communication channel.

Since:
1.7

connectForCommunicationChannel

public abstract java.net.Socket connectForCommunicationChannel(java.lang.String host,
                                                               int port)
                                                        throws java.io.IOException
This methods returns an established connection to a remote host, suitable for a FTP communication channel.

Parameters:
host - The remote host name or address.
port - The remote port.
Returns:
The connection with the remote host.
Throws:
java.io.IOException - If the connection cannot be established.

connectForDataTransferChannel

public abstract java.net.Socket connectForDataTransferChannel(java.lang.String host,
                                                              int port)
                                                       throws java.io.IOException
This methods returns an established connection to a remote host, suitable for a FTP data transfer channel.

Parameters:
host - The remote host name or address.
port - The remote port.
Returns:
The connection with the remote host.
Throws:
java.io.IOException - If the connection cannot be established.