Class SftpFileSystem
java.lang.Object
com.northconcepts.datapipeline.core.DataObject
com.northconcepts.datapipeline.core.Endpoint
com.northconcepts.datapipeline.internal.lang.FileSystem
com.northconcepts.datapipeline.filesystem.sftp.SftpFileSystem
Class for accessing the SFTP 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
ConstructorsConstructorDescriptionSftpFileSystem(String hostName, int port) Connects to the specified SFTP server with credentials supplied through aCredentialsResolver(seesetCredentialsResolver(CredentialsResolver)).SftpFileSystem(String hostName, int port, String userName, String password) Connects to the specified SFTP server.SftpFileSystem(String userName, String password) Connects to the specified SFTP server at localhost, default port 22. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the connection from an SFTP server.List<SftpClient.DirEntry> listFolder(String folderName) Returns the contents of the folder.List<SftpClient.DirEntry> Returns the contents of the root folder.voidopen()Opens a connection to an SFTP 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.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
-
SftpFileSystem
Connects to the specified SFTP server at localhost, default port 22.- Parameters:
userName- name of the userpassword- password of the user
-
SftpFileSystem
Connects to the specified SFTP server.- Parameters:
hostName- hostname of the SFTP serverport- the port to connect touserName- name of the userpassword- password of the user
-
SftpFileSystem
Connects to the specified SFTP server with credentials supplied through aCredentialsResolver(seesetCredentialsResolver(CredentialsResolver)).- Parameters:
hostName- hostname of the SFTP serverport- the port to connect to
-
-
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 SFTP server.- Overrides:
openin classEndpoint- Throws:
DataException
-
close
Closes the connection from an SFTP 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
- 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
- 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
-