Package dk.netarkivet.common.distribute
Class FTPRemoteFile
- java.lang.Object
-
- dk.netarkivet.common.distribute.AbstractRemoteFile
-
- dk.netarkivet.common.distribute.FTPRemoteFile
-
- All Implemented Interfaces:
RemoteFile
,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
Fields Modifier and Type Field Description protected 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
appendTo(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.String
getChecksum()
Get checksum for file, or null if checksums were not requested.InputStream
getInputStream()
An implementation of the getInputStream operation that works with FTP.static RemoteFile
getInstance(File localFile, Boolean useChecksums, Boolean fileDeletable, Boolean multipleDownloads)
Create a remote file that handles the transport of the remote file data.static RemoteFile
getInstance(File localFile, Boolean useChecksums, Boolean fileDeletable, Boolean multipleDownloads, RemoteFileSettings connectionParams)
int
getNumberOfRetries()
Retrieval of the number of retries for retrieving a file from a FTP server.static RemoteFileSettings
getRemoteFileSettings()
String
toString()
Return a human-readable description of the object.-
Methods inherited from class dk.netarkivet.common.distribute.AbstractRemoteFile
copyTo, getName, getSize
-
-
-
-
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 String checksum
If useChecksums is true, contains the file checksum.
-
-
Method Detail
-
getInstance
public static RemoteFile getInstance(File localFile, Boolean useChecksums, Boolean fileDeletable, 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 fileuseChecksums
- 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(File localFile, Boolean useChecksums, Boolean fileDeletable, Boolean multipleDownloads, RemoteFileSettings connectionParams) throws IOFailure
- Throws:
IOFailure
-
getInputStream
public 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 interfaceRemoteFile
- Specified by:
getInputStream
in classAbstractRemoteFile
- 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(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 interfaceRemoteFile
- Overrides:
appendTo
in classAbstractRemoteFile
- 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 interfaceRemoteFile
- Specified by:
cleanup
in classAbstractRemoteFile
-
toString
public String toString()
Return a human-readable description of the object.- Overrides:
toString
in classAbstractRemoteFile
- Returns:
- description of object -- not machine readable
-
getChecksum
public String getChecksum()
Get checksum for file, or null if checksums were not requested.- Specified by:
getChecksum
in interfaceRemoteFile
- Specified by:
getChecksum
in classAbstractRemoteFile
- 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 classAbstractRemoteFile
- Returns:
- The number of retries for the FTP connection, defined in settings.
-
getRemoteFileSettings
public static RemoteFileSettings getRemoteFileSettings()
-
-