Introduction
Using the FileSystemOperations class you can do lots of different tasks on any type of file system on any host. Some of these tasks are:
- create file in variety of ways
- append or replace text in file
- manipulate file attributes like modification time, UID, GIU
- rename and delete files and directories
- read the whole file content
- extract content from a file in a way similar to the Linux grep command
- read the new file content - useful for watching log files
- copy files/directories
Dependency note
This functionality is part of ATS Action library module. In order to use it you have to import it into classpath. For Maven the dependency needed is:
<dependency>
<groupId>com.axway.ats.framework</groupId>
<artifactId>ats-actionlibrary</artifactId>
<version>${ats.version}</version> <!-- set specific ATS version in ats.version property. Example: 4.0.3 -->
</dependency>
First make an instance of the FileSystemOperations class:
FileSystemOperations fileOperations =
new
FileSystemOperations( SERVER_IP );
|
Examples
Following are some example of what you can do with this class. For the full list please check the code or JavaDoc.
import com.axway.ats.action.filesystem.FileSystemOperations; ... // Make an instance of this class FileSystemOperations fileOperations = new FileSystemOperations( SERVER_IP ); // create a remote folder fileOperations.createDirectory( SOME_DIRECTORY ); // copy a local file to the remote folder fileOperations.copyFileTo( SOME_FILE, SOME_DIRECTORY ); // get the MD5 sum of the remote file String md5Sum = fileOperations.computeMd5Sum( SOME_FILE, Md5SumMode.ASCII ); // get the last 3 lines of the remote file String[] last3Lines = fileOperations.getLastLinesFromFile( SOME_FILE, 3 ); // check whether some file exists fileOperations.doesFileExist( SOME_FILE ); // delete the remote file fileOperations.deleteFile( SOME_FILE ); // get all lines from the file which contain "first name = " String[] matchedLines = fileOperations.fileGrep( SOME_FILE, ".*first name = .*", false); // get a list of all XML files from the specified folder and its subfolders String[] foundFiles = fileOperations.findFiles( SOME_FOLDER, ".*.XML", true, false, true ); // Get info about all matches (in this case it will return all instances of the specified String) // This method remembers the last processed line, so the next call will continue from after that line, // which makes it good for extracting info from growing(log like) files when you need to check only the new content FileMatchInfo matchInfo = fileOperations.findNewTextInFile( SOME_FILE, "Our server started successfully", true ); // the list of matched lines can be taken from the returned matchInfo structure // copy a file from a remote host to another remote host - of course the ATS Agent must be running on both remote hosts fileOperations.copyRemoteFile( FROM_HOST, SOME_FILE, TO_HOST, SOME_FILE ); // copy recursively a folder from a remote host to another remote host - of course the ATS Agent must be running on both remote hosts fileOperations.copyRemoteDirectory( FROM_HOST, SOME_FOLDER, TO_HOST, SOME_FOLDER, true );
Special considerations when copying files and directories
For details when copying files to Docker containers you may refer to this page
Back to parent page
Go to Table of Contents