Class FtpFileSystem
java.lang.Object
com.northconcepts.datapipeline.core.DataObject
com.northconcepts.datapipeline.core.Endpoint
com.northconcepts.datapipeline.internal.lang.FileSystem
com.northconcepts.datapipeline.filesystem.ftp.FtpFileSystem
Class for accessing the FTP file system.
-
Field Summary
Fields inherited from class com.northconcepts.datapipeline.core.Endpoint
BUFFER_SIZE, captureElapsedTime, DEFAULT_READ_BUFFER_SIZEFields inherited from class com.northconcepts.datapipeline.core.DataObject
id, log, name, TIMESTAMP_FORMAT -
Constructor Summary
ConstructorsConstructorDescriptionConnects to the FTP server on localhost (port 21) as an anonymous user.FtpFileSystem(String hostName, int port) Connects to the specified FTP server with credentials supplied through aCredentialsResolver(seesetCredentialsResolver(CredentialsResolver)).FtpFileSystem(String hostName, int port, String userName, String password) Connects to the specified FTP server. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the connection from an FTP server.Returns the data connection mode applied atopen()(defaults toDataConnectionMode.ACTIVE_LOCAL).Returns the file transfer mode applied atopen()(defaults toFileTransferMode.STREAM).Returns the file transfer type applied atopen()(defaults toFileTransferType.BINARY).booleanIndicates if data connections must be with the same host as the control connection, applied atopen()(defaults to true).List<FTPFile> listFolder(String folderName) Returns the contents of the folder.List<FTPFile> Returns the contents of the root folder.voidopen()Opens a connection to an FTP server.Reads the specified file in the root folder.Reads a file in the specified folder.setCredentialsResolver(CredentialsResolver credentialsResolver) Sets the resolver supplying this file system's user name and password (Credentials.USERNAME/Credentials.PASSWORD) — resolved on eachopen(), never at construction, so rotated secrets are picked up on the next connection.setDataConnectionMode(DataConnectionMode dataConnectionMode) setFileTransferMode(FileTransferMode fileTransferMode) SeeFileTransferModesetFileTransferType(FileTransferType fileTransferType) SeeFileTransferTypesetRemoteVerification(boolean remoteVerification) Indicates if data connections must be with the same host as the control connection, applied atopen()(defaults to true).Writes a file to the root folder.Writes a file to the specified folder.Methods inherited from class com.northconcepts.datapipeline.internal.lang.FileSystem
credentialValue, getCredentialsResolver, getCurrentCredentials, refreshCredentials, resolveCredentialsMethods inherited from class com.northconcepts.datapipeline.core.Endpoint
addElapsedtime, addExceptionProperties, assertClosed, assertNotOpened, assertOpened, finalize, getClosedOn, getDescription, getElapsedTime, getElapsedTimeAsString, getNestedEndpoint, getOpenedOn, getOpenElapsedTime, getOpenElapsedTimeAsString, getRootEndpoint, getSelfTime, getSelfTimeAsString, getState, isCaptureElapsedTime, isClosed, isOpen, setCaptureElapsedTime, setDescription, toString
-
Constructor Details
-
FtpFileSystem
public FtpFileSystem()Connects to the FTP server on localhost (port 21) as an anonymous user. -
FtpFileSystem
Connects to the specified FTP server with credentials supplied through aCredentialsResolver(seesetCredentialsResolver(CredentialsResolver)).- Parameters:
hostName- hostname of the FTP serverport- the port to connect to
-
FtpFileSystem
Connects to the specified FTP server.- Parameters:
hostName- hostname of the FTP serverport- the port to connect touserName- name of the userpassword- password of the user
-
-
Method Details
-
setCredentialsResolver
Sets the resolver supplying this file system's user name and password (Credentials.USERNAME/Credentials.PASSWORD) — resolved on eachopen(), never at construction, so rotated secrets are picked up on the next connection. Keys absent from the resolved credentials fall back to the constructor-supplied values.- Overrides:
setCredentialsResolverin classFileSystem
-
open
Opens a connection to an FTP server.- Overrides:
openin classEndpoint- Throws:
DataException
-
close
Closes the connection from an FTP server.- Overrides:
closein classFileSystem- Throws:
DataException
-
readFile
Reads a file in the specified folder. To specify a nested folder use "/" as separator.
Example:
- readFile("folderOne", "fileName") - reads the file in folderOne which is under the root folder
- readFile("folderOne/folderTwo", "fileName") - reads the file in folderTwo which is under folderOne
- readFile("/folderOne/folderTwo", "fileName") - reads the file in folderTwo which is under folderOne
- Returns:
- an
InputStreamornull - Throws:
Throwable
-
readFile
Reads the specified file in the root folder.- Returns:
- an
InputStreamornull - Throws:
Throwable
-
listFolder
Returns the contents of the folder. To specify a nested folder use "/" as separator.
Example:
- listFolder("folderOne") - reads the contents of folderOne which is under the root folder
- listFolder("folderOne/folderTwo") - reads the contents of folderTwo which is under folderOne
- listFolder("/folderOne/folderTwo") - reads the contents of folderTwo which is under folderOne
- Throws:
Throwable
-
listRootFolder
Returns the contents of the root folder.- Throws:
Throwable
-
writeFile
Writes a file to the root folder. If there is a file with the same name, it is overwritten.- Parameters:
fileName- the name of the file- Throws:
Throwable
-
writeFile
Writes a file to the specified folder. If there is a file with the same name, it is overwritten.- Parameters:
folderName- the folder namefileName- the name of the file- Throws:
Throwable
-
getDataConnectionMode
Returns the data connection mode applied atopen()(defaults toDataConnectionMode.ACTIVE_LOCAL). -
setDataConnectionMode
-
getFileTransferType
Returns the file transfer type applied atopen()(defaults toFileTransferType.BINARY). -
setFileTransferType
SeeFileTransferType -
getFileTransferMode
Returns the file transfer mode applied atopen()(defaults toFileTransferMode.STREAM). -
setFileTransferMode
SeeFileTransferMode- Parameters:
fileTransferMode-
-
isRemoteVerification
public boolean isRemoteVerification()Indicates if data connections must be with the same host as the control connection, applied atopen()(defaults to true). -
setRemoteVerification
Indicates if data connections must be with the same host as the control connection, applied atopen()(defaults to true).
-