public class SftpConnector extends Object
| Modifier and Type | Field and Description |
|---|---|
protected SftpConfiguration |
sftpConfiguration |
| Constructor and Description |
|---|
SftpConnector() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
connect()
Open sftpConnection to a sftp-server.
|
void |
deleteFile(String path,
String fileName)
Deletes a file from sftp-server.
|
void |
deleteFiles(String path,
List<String> fileNames)
Deletes a file from sftp-server.
|
protected void |
disconnect()
Close existing sftpConnection.
|
void |
downloadFile(Path source,
Path destination)
Downloads a file from the SFTP server to the local disc.
|
Boolean |
fileExists(String path,
String fileName)
Check if file exists in path.
|
byte[] |
getFileContent(String path,
String fileName)
Return the content of a Streamfile.
|
List<String> |
getFileNamesFromPath(String path)
Retrieves all file names.
|
List<String> |
getFileNamesFromPath(String path,
Pattern fileNamePattern)
Retrieves all file names with file name pattern criteria
|
Map<String,Date> |
getFileNamesFromPath(String path,
Pattern fileNamePattern,
Date onlyOlderThan)
Returns all files in a folder on stfp-server.
|
Map<String,Date> |
getFileNamesFromPathOlderThan(String path,
Date onlyOlderThan)
Retrieves all file names with date criteria.
|
int |
getPriority() |
void |
init(SftpConfiguration sftpConfiguration)
Initializer method.
|
protected void |
innerUploadFile(byte[] fileContent,
String path,
String fileName) |
boolean |
isActive()
Check the connector state based on current local time, whether it is currently deactivated by configuration
|
void |
moveFile(String oldPath,
String newPath,
String fileName)
Moves a file to another path on the SFTP server.
|
void |
preDestroy()
Automatic disconnect
|
void |
renameFile(String path,
String oldFilename,
String newFileName)
Moves a file to another path on the SFTP server.
|
void |
uploadFile(byte[] fileContent,
String fileName)
Uploads a file to the sftp-server in default directory.
|
void |
uploadFile(byte[] fileContent,
String path,
String fileName)
Uploads a file to the sftp-server.
|
protected SftpConfiguration sftpConfiguration
@PreDestroy public void preDestroy()
public void init(SftpConfiguration sftpConfiguration)
sftpConfiguration - configuration valuespublic void uploadFile(byte[] fileContent,
String fileName)
fileContent - content of the file (example: asd123qwefffxyc)fileName - name of the file on the server (example: REQ1and1654300.CAS)public void uploadFile(byte[] fileContent,
String path,
String fileName)
fileContent - content of the file (example: asd123qwefffxyc)path - relative target-path on the sftp-server (example: out/)fileName - name of the file on the server (example: REQ1and1654300.CAS)public void deleteFile(String path, String fileName)
path - relative target-path on the sftp-server (example: in/)fileName - name of the file on the server (example: RSP1and16543000.CAS)RuntimeExceptionpublic void deleteFiles(String path, List<String> fileNames)
path - relative target-path on the sftp-server (example: in/)fileNames - name of the file on the server (example: RSP1and16543000.CAS)RuntimeExceptionpublic void moveFile(String oldPath, String newPath, String fileName)
oldPath - the current path of the filenewPath - the destination path to move the file tofileName - the file to movepublic void renameFile(String path, String oldFilename, String newFileName)
path - the current path of the fileoldFilename - the old file namenewFileName - the new file namepublic List<String> getFileNamesFromPath(String path)
path - path to retrieve frompublic Map<String,Date> getFileNamesFromPathOlderThan(String path, Date onlyOlderThan)
path - path to retrieve fromonlyOlderThan - date criteriapublic List<String> getFileNamesFromPath(String path, Pattern fileNamePattern)
path - path to retrieve fromfileNamePattern - file name pattern criteriapublic Map<String,Date> getFileNamesFromPath(String path, Pattern fileNamePattern, Date onlyOlderThan)
path - relative target-path on the sftp-server (example: in/)fileNamePattern - file name pattern criteriaonlyOlderThan - date criteriaRuntimeExceptionpublic Boolean fileExists(String path, String fileName) throws RuntimeException
path - relative target-path on the sftp-server (example: in/)fileName - name of the file on the server (example: RSP1and16543000.CAS)RuntimeException - if can not check existencepublic byte[] getFileContent(String path, String fileName)
path - relative target-path on the sftp-server (example: in/)fileName - name of the file on the server (example: RSP1and16543000.CAS)RuntimeExceptionpublic void downloadFile(Path source, Path destination)
source - relative file path on the SFTP serverdestination - file path on the local discpublic boolean isActive()
true if connector is currently activepublic int getPriority()
protected void connect()
RuntimeExceptionprotected void disconnect()
Copyright © 2017–2020. All rights reserved.