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 int FTP_DATATIMEOUT
          How large a data timeout on our FTP connections.
static int FTP_RETRIES
          How many times we will retry upload, download, and logon.
 
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.
static RemoteFile getInstance(java.io.File localFile, java.lang.Boolean useChecksums, java.lang.Boolean fileDeletable, java.lang.Boolean multipleDownloads, RemoteFileSettings connectionParams)
           
 int getNumberOfRetries()
          Retrieval of the number of retries for retrieving a file from a FTP server.
static RemoteFileSettings getRemoteFileSettings()
           
 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

FTP_RETRIES

public static int FTP_RETRIES
How many times we will retry upload, download, and logon.


FTP_DATATIMEOUT

public static int FTP_DATATIMEOUT
How large a data timeout on our FTP connections.


checksum

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

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

getInstance

public static RemoteFile getInstance(java.io.File localFile,
                                     java.lang.Boolean useChecksums,
                                     java.lang.Boolean fileDeletable,
                                     java.lang.Boolean multipleDownloads,
                                     RemoteFileSettings connectionParams)
                              throws IOFailure
Throws:
IOFailure

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.

getRemoteFileSettings

public static RemoteFileSettings getRemoteFileSettings()