dk.netarkivet.common.distribute
Class FTPRemoteFile

java.lang.Object
  extended by dk.netarkivet.common.distribute.AbstractRemoteFile
      extended by dk.netarkivet.common.distribute.FTPRemoteFile
All Implemented Interfaces:
RemoteFile, java.io.Serializable

public final class FTPRemoteFile
extends AbstractRemoteFile

Class encapsulating upload to & download from an ftp-server. Transfers are done using binary type and passive mode, if available.

See Also:
Serialized Form

Field Summary
protected  java.lang.String checksum
          If useChecksums is true, contains the file checksum.
static java.lang.String FTP_DATATIMEOUT_SETTINGS
          settings.common.remoteFile.datatimeout:
The setting for the FTP data timeout in seconds.
static java.lang.String FTP_RETRIES_SETTINGS
          settings.common.remoteFile.retries:
The setting for the number of times FTPRemoteFile should try before giving up a copyTo operation or logOn operation.
static java.lang.String FTP_SERVER_NAME
          settings.common.remoteFile.serverName:
The setting for the FTP-server used.
static java.lang.String FTP_SERVER_PORT
          settings.common.remoteFile.serverPort:
The setting for the FTP-server port used.
static java.lang.String FTP_USER_NAME
          settings.common.remoteFile.userName:
The setting for the FTP username.
static java.lang.String FTP_USER_PASSWORD
          settings.common.remoteFile.userPassword:
The setting for the FTP password.
 
Fields inherited from class dk.netarkivet.common.distribute.AbstractRemoteFile
file, fileDeletable, filesize, multipleDownloads, useChecksums
 
Method Summary
 void appendTo(java.io.OutputStream out)
          Write the contents of this ftp remote file to an output stream.
 void cleanup()
          Cleanup will delete the file on the FTP server.
 java.lang.String getChecksum()
          Get checksum for file, or null if checksums were not requested.
 java.io.InputStream getInputStream()
          An implementation of the getInputStream operation that works with FTP.
static RemoteFile getInstance(java.io.File localFile, java.lang.Boolean useChecksums, java.lang.Boolean fileDeletable, java.lang.Boolean multipleDownloads)
          Create a remote file that handles the transport of the remote file data.
 int getNumberOfRetries()
          Retrieval of the number of retries for retrieving a file from a FTP server.
 java.lang.String toString()
          Return a human-readable description of the object.
 
Methods inherited from class dk.netarkivet.common.distribute.AbstractRemoteFile
copyTo, getName, getSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

checksum

protected final java.lang.String checksum
If useChecksums is true, contains the file checksum.


FTP_SERVER_NAME

public static java.lang.String FTP_SERVER_NAME
settings.common.remoteFile.serverName:
The setting for the FTP-server used.


FTP_SERVER_PORT

public static java.lang.String FTP_SERVER_PORT
settings.common.remoteFile.serverPort:
The setting for the FTP-server port used.


FTP_USER_NAME

public static java.lang.String FTP_USER_NAME
settings.common.remoteFile.userName:
The setting for the FTP username.


FTP_USER_PASSWORD

public static java.lang.String FTP_USER_PASSWORD
settings.common.remoteFile.userPassword:
The setting for the FTP password. *


FTP_RETRIES_SETTINGS

public static java.lang.String FTP_RETRIES_SETTINGS
settings.common.remoteFile.retries:
The setting for the number of times FTPRemoteFile should try before giving up a copyTo operation or logOn operation.


FTP_DATATIMEOUT_SETTINGS

public static java.lang.String FTP_DATATIMEOUT_SETTINGS
settings.common.remoteFile.datatimeout:
The setting for the FTP data timeout in seconds. The default value is 600 (10 minutes).

Method Detail

getInstance

public static RemoteFile getInstance(java.io.File localFile,
                                     java.lang.Boolean useChecksums,
                                     java.lang.Boolean fileDeletable,
                                     java.lang.Boolean multipleDownloads)
                              throws IOFailure
Create a remote file that handles the transport of the remote file data. This method is used by the sender to prepare the transport.

Parameters:
localFile - File object for the remote file
useChecksums - If true, checksums will be used to check transfers.
fileDeletable - If true, this file will be deleted after upload to FTP.
multipleDownloads - If true, the file will not be removed from FTP server automatically after first download.
Returns:
FTPRemoteFile object
Throws:
IOFailure - if FTPRemoteFile creation fails

getInputStream

public java.io.InputStream getInputStream()
An implementation of the getInputStream operation that works with FTP. Notice that most of the special work (logging out and checking MD5) happens in the close() method of the returned InputStream, since that is the only place where we can know we're done.

Specified by:
getInputStream in interface RemoteFile
Specified by:
getInputStream in class AbstractRemoteFile
Returns:
An InputStream that will deliver the data transferred by FTP. Holding on to this for long periods without reading any data might cause a timeout.

appendTo

public void appendTo(java.io.OutputStream out)
Write the contents of this ftp remote file to an output stream. Notice that while the checksum of the transferred data is checked, no retries are performed, and in case of failure, there is no guarantee that any data have been transferred.

Specified by:
appendTo in interface RemoteFile
Overrides:
appendTo in class AbstractRemoteFile
Parameters:
out - OutputStream that the data will be written to. This stream will not be closed by this operation.
Throws:
IOFailure - If append operation fails

cleanup

public void cleanup()
Cleanup will delete the file on the FTP server. This method should never throw exceptions. It is idempotent, meaning it can be called twice without trouble.

Specified by:
cleanup in interface RemoteFile
Specified by:
cleanup in class AbstractRemoteFile

toString

public java.lang.String toString()
Return a human-readable description of the object.

Overrides:
toString in class java.lang.Object
Returns:
description of object -- do not machineparse.

getChecksum

public java.lang.String getChecksum()
Get checksum for file, or null if checksums were not requested.

Specified by:
getChecksum in interface RemoteFile
Specified by:
getChecksum in class AbstractRemoteFile
Returns:
checksum for file, or null if checksums were not requested.

getNumberOfRetries

public int getNumberOfRetries()
Retrieval of the number of retries for retrieving a file from a FTP server. Returns the setting for number of retries.

Specified by:
getNumberOfRetries in class AbstractRemoteFile
Returns:
The number of retries for the FTP connection, defined in settings.