In this article
...
You can use this Snap to perform a file operation (move/copy/rename) for a file from a source to a target in the same server. The supported file protocols are: local file (file:///), FTP, SFTP, S3, WASB, and WASBS.
...
Info |
---|
The File Operation Snap performs extract and load operations on the input file or folder. |
...
This Snap does not support using the ABFS protocol with a Windows-based Snaplex.
When you use special characters, such asðø©¢¾A²½µ®÷¶þ~ for Source and Target directory and filenames, this Snap fails and results in the following error as the special characters are not supported.
Error: Illegal character in fragment at index 71:
abfs://bigdataqa@bigdataqassl.dfs.core.windows.net/simplechar/owner!@#$^&()_¢äâêîôûñç¡¿ÉÙËǨ°¸ðø©¢¾A²½µ®§÷¶þ~.json
The format: abfs(s)://filesystem@accountname.endpoint/<path>
for file path for Source and Target fields does not work as this URL syntax is not supported. The file protocol must begin with abfs(s):///,
else the container, account name, and endpoint are interpolated into the URL at runtime, which results in the following error.
Error: Unsupported protocol or URL syntax error in abfs(s)://filesystem@accountname.endpoint/<path>
,
Workaround: Use the supported file protocol and correct URL syntaxin abfs(s)://filesystem@accountname.endpoint/<path>
,
Workaround: Use the supported file protocol and correct URL syntax.
SnapLogic Pipelines configured with a SnapLogic instance that are communicating with the Solarwinds Serv-U SFTP server can no longer communicate with the server as it is upgraded to Serv-U version 15.3.2, which is incompatible with the JSCH library in SnapLogic. The SnapLogic Binary Snap Pack does not support JSCH 15.3.2 and above. To resolve this issue, you can either use the SolarWinds 15.3.2 patch or roll back the update to 15.3.2. Learn more about this issue: Success Center.
Snap Views
Type | Format | Number of Views | Examples of Upstream and Downstream Snaps | Description |
---|
Input | Document | Min: 0 Max: 1 | | Any document with key-value pairs to evaluate expression properties in the File Operator Snap can be used, where each input document will cause one complete execution of the Snap. |
Output | Document | Min: 0 Max: 1 | CSV Formatter JSON Formatter Mapper
| A typical output from this Snap is a document with column headers, such as Source, Target, and Status (Moved or Copied). Expand |
---|
title | Sample output example |
---|
|
Paste code macro |
---|
| {
"Source": "ftp://ftp.snaplogic.com/home/mrtest/new1/sample.csv",
"Target": "ftp://ftp.snaplogic.com/home/mrtest/new2/new.csv",
"Status": "Moved"
} |
|
|
Error | Error handling is a generic way to handle errors without losing data or failing the Snap execution. You can handle the errors that the Snap might encounter while running the Pipeline by choosing one of the following options from the When errors occur list under the Views tab. The available options are: Stop Pipeline Execution: Stops the current pipeline execution when the Snap encounters an error. Discard Error Data and Continue: Ignores the error, discards that record, and continues with the rest of the records. Route Error Data to Error View: Routes the error data to an error view without stopping the Snap execution.
Learn more about Error handling in Pipelines. |
...
Field Name | Field Type | Description |
---|
Label* Default Value: File Operation Example: File Operation | String | Specify the name for the Snap. You can modify this to be more specific, especially if you have more than one of the same Snap in your Pipeline. |
Source* Default Value: [None] Example: | String/Expression | Specify the URL for the source, where the binary data is read from. This Snap also supports S3 Virtual Private Cloud (VPC) endpoint. For example, s3://my-bucket@bucket.vpce-028b7814794578709-vu0vvauy.s3.us-west-2.vpce.amazonaws.com Example of Source as an expression: " s3:///mybucket/out_" + Date.now() + ".csv" the evaluated filename will be: s3:///mybucket/out_2013-11-13T00:22:31.880Z.csv This property should have the syntax: scheme://[hostname:port]/[path to source] You can also copy or move the file from your local system to Azure blob container for better performance. Note |
---|
When using expressions to build a file name, ensure that the resulting file name does not contain characters that are not supported by the target platform. |
Warning |
---|
Amazon AWS S3 SDK Limitation - File operationsWhen performing operations on S3 folders ensure that a trailing forward slash ( / ) is added; otherwise, the Snap considers it a file instead of a folder and an error message will be displayed. Ensure the source does not contain '?' character because it is not fully supported and when present, the Snap might fail.
|
|
Target* Default Value: [None] Example: | String/Expression | This property specifies the URL of the destination where the selected file operation must be performed. This Snap also supports S3 Virtual Private Cloud (VPC) endpoint. For example, s3://my-bucket@bucket.vpce-028b7814794578709-vu0vvauy.s3.us-west-2.vpce.amazonaws.com Warning |
---|
Amazon AWS S3 SDK Limitation - File operationsWhen performing operations on S3 folders ensure that a trailing forward slash ( / ) is added; otherwise, the Snap considers it a file instead of a folder and an error message will be displayed. Ensure the file name, folder name, or the file path does not contain '?' character because it is not supported. The Snap fails with an error if you include the '?' character.
|
|
File Operation Default valueValue: Move Example: | String/Expression | Enter or select the operation you want the Snap to perform on the file. Available options are: Move - Moves the source file to the target location. Copy - Creates a copy of the source file in the target location. Rename - Renames a file in the source location. Rename is handled the same as Move. The source URL and target URL are the same, with the exception of the file name.
Info |
---|
This Snap supports Azure Data Lake Storage (ADLS) Gen 2 Storage and ADLS Gen 2 Storage (ABFS) protocol for moving and copying files in the Azure Blob File System (ABFS). |
Note |
---|
Rename is handled the same as Move. The source URL and target URL are the same, with the exception of the file name. |
|
Error if exists Default valueValue: Selected Example: Deselected | Checkbox | If enabled, the Snap displays an error when the target exists. If disabled, the Snap replaces or overwrites the target with the source. |
Advanced Properties
| Use this field set to customize or control the Snap's validation and execution mechanism. |
Properties Default Value: SAS URI Example: Simple file operation
| Dropdown list | The available options are: Multiexcerpt include macro |
---|
name | SASURI_Description |
---|
page | File Reader |
---|
|
Info |
---|
If the SAS URI value is provided in the Snap settings, then the settings provided in the account (if any account is attached) are ignored. |
Info |
---|
If Simple file operation is set to true, The selection for Error if exists property is ignored. None of the logic described in Snap Behavior for Key Operations applies. The exact behavior of the Snap varies depending on the File Server implementation and its administration settings.
|
Az copy absolute path: Specify the directory and wildcard for Azure blob storage for Copy, Move, and Rename operations. For example, "\t" + blob_demo
You can also copy or move the file from your local system to Azure blob container for better performance. Note |
---|
This field is applicable only if you are using Azure Storage account for this Snap. |
Info |
---|
You must install the Azcopy utility in the Snaplex for fetching the path. If the path is null, native Azure Storage SDK is used for all operations. If you specify '/' in this field, the Snap searches for Azcopy in the path or in the specified path and runs the Azcopy command. You can use https as a valid URL, as Azcopy supports https file system. Learn more about Az copy command. Azure storage SDK does not support file system for https . So, when you do not provide Azcopy absolute path and Source/Target URL is https , the Snap displays an error. For this to work along with the container URL of the Azure blob, you must provide SAS URI under the Advanced properties field set for proper authentication.
|
|
Values Default Value:[None]Example: | String/Expression | Specify a value for the above property. |
Snap Execution | Dropdown list | Multiexcerpt include macro |
---|
name | Execution_Detail_Write |
---|
page | SOAP Execute |
---|
|
|
...
Note |
---|
State TablesFollowing is a collection of state tables to depict the Snap's behavior for different configurations of the Source, Target and Error if exists properties. These combinations are applied to move, and copy operations. Use the following legend to understand what the values mean: |
Source | Target | Error if exists |
---|
-- | -- | x | State does not affect outcome | x | State does not affect outcome |
00 | Does not exist | 00 | Does not exist | 0 | Not selected |
01 | Regular file | 01 | Regular file | 1 | Selected |
10 | Directory | 10 | Empty directory | -- | -- |
-- | -- | 11 | Non-empty directory | -- | -- |
...
FTP, SFTP, and File Protocols
Expand |
---|
|
Move OperationS. No. | Source | Target | Error if exists | Snap's Behavior |
---|
Status | Description |
---|
1 | 00 | x | x | Error | Source not found. | 2 | 01 | 00 | x | Moved | -- | 3 | 01 | 01 | 0 | Moved | Target file is overwritten. | 4 | 01 | 01 | 1 | Error | Target already exists. | 5 | 01 | 10 | 0 | Moved | Empty target directory is replaced with a new file of the same name. | 6 | 01 | 10 | 1 | Error | Target already exists. | 7 | 01 | 11 | 0 | Error | Target directory not empty. | 8 | 01 | 11 | 1 | Error | Target already exists. | 9 | 10 | 00 | x | Moved | -- Note |
---|
The source directory is renamed to the given target path if the target’s parent directory is not a subdirectory of the source. |
| 10 | 10 | 01 | 0 | Moved | Target file is removed and source directory is moved to the target directory. | 11 | 10 | 01 | 1 | Error | Target already exists. | 12 | 10 | 10 | 0 | Moved | Empty target directory is replaced with source directory. | 13 | 10 | 10 | 1 | Error | Target already exists. | 14 | 10 | 11 | 0 | Error | Target directory not empty. | 15 | 10 | 11 | 1 | Error | Target already exists. |
|
...
Expand |
---|
|
Copy OperationS. No. | Source | Target | Error if exists | Snap's Behavior |
---|
Status | Description |
---|
1 | 00 | x | x | Error | Source not found. | 2 | 01 | 00 | x | Copied | Target file is created. | 3 | 01 | 01 | 0 | Copied | Target file is overwritten. | 4 | 01 | 01 | 1 | Error | Target already exists. | 5 | 01 | 10 | 0 | Copied | Empty target directory is replaced with a new file of the same name. Note |
---|
For some SFTP file servers, the Snap may produce an error with the following Reason: "Cannot open output stream for <target path>" if the Target property value ends with '/'. |
| 6 | 01 | 10 | 1 | Error | Target already exists. | 7 | 01 | 11 | 0 | Error | Target directory not empty. | 8 | 01 | 11 | 1 | Error | Target already exists. | 9 | 10 | 00 | x | Copied | Empty target directory created. | 10 | 10 | 01 | 0 | Copied | Target file replaced with an empty directory of the same name. | 11 | 10 | 01 | 1 | Error | Target already exists. | 12 | 10 | 10 | 0 | No operation | Empty target directory remains the same. | 13 | 10 | 10 | 1 | Error | Target already exists. | 14 | 10 | 11 | 0 | Error | Target directory not empty. | 15 | 10 | 11 | 1 | Error | Target already exists. |
|
...
Expand |
---|
|
Move OperationS. No. | Source | Target | Error if exists | Snap's Behavior |
---|
Status | Description |
---|
1 | 00 | x | x | Error | Source not found. | 2 | 01 | 00 | x | Moved | -- | 3 | 01 | 01 | 0 | Moved | Target file is overwritten. | 4 | 01 | 01 | 1 | Error | Target already exists. | 5 | 01 | 10 | x | Moved | Source file is moved to the target directory. | 6 | 01 | 11 | 0 | Moved | Source file is moved to the target directory. | 7 | 01 | 11 | 1 | Moved or Error | Error if a file with the same name already exists in the target directory. | 8 | 10 | 00 | x | Moved | All files in the source directory are moved to the target directory. | 9 | 10 | 01 | 0 | Moved | A new target directory with a name same as the target file is created and all files in the source directory are moved to the target directory. As a result, a regular file and a directory with the same name will coexist in the target. | 10 | 10 | 01 | 1 | Error | Target already exists. | 11 | 10 | 10 | x | Moved | All files in the source directory are moved to the target directory. | 12 | 10 | 11 | 0 | Moved | All files in the source directory are moved to the target directory. | 13 | 10 | 11 | 1 | Moved or Error | Error if a file with the same name already exists in the target directory. |
|
...
Expand |
---|
|
Copy OperationS. No. | Source | Target | Error if exists | Snap's Behavior |
---|
Status | Description |
---|
1 | 00 | x | x | Error | Source not found. | 2 | 01 | 00 | x | Copied | Target file is created. | 3 | 01 | 01 | 0 | Copied | Target file is overwritten. | 4 | 01 | 01 | 1 | Error | Target already exists. | 5 | 01 | 10 | x | Copied | Source file is copied to the target directory. | 6 | 01 | 11 | 0 | Copied | Source file is copied to the target directory. | 7 | 01 | 11 | 1 | Copied or Error | Error if the file of the same name exists in the target directory already. | 8 | 10 | 00 | x | Copied | All files in the source directory are copied to the target directory. | 9 | 10 | 01 | 0 | Copied | A new target directory with a name same as the target file is created and all files in the source directory are copied to the target directory. As a result, a regular file and a directory with the same name will coexist in the target. | 10 | 10 | 01 | 1 | Error | Target already exists. | 11 | 10 | 10 | x | Copied | All files in the source directory are copied to the target directory. | 12 | 10 | 11 | 0 | Copied | All files in the source directory are copied to the target directory. | 13 | 10 | 11 | 1 | Copied or Error | Error if the file of the same name exists in the target directory already. |
|
...
Configure the File Reader Snap that reads airlines.csv file from the local machine.
Next, we configure the File Writer Snap to write the airlines.csv file.
Next, we configure the File Operation Snap to move the file from Source (local directory) to Target (Azure Blob container).
Copying and Moving of File from One Folder to Another Folder
This example Pipeline demonstrates copying and moving of files with ABFS protocol from one folder to another folder.
First, we configure the JSON Generator Snap to pass the following sample data. After validation we see the following output.
Image RemovedImage Added | Image RemovedImage Added |
Next, we format the data using the JSON Formatter Snap and then, use the HDFS Writer Snap to write the sample file (that uses ABFS protocol and ADLS Gen 2) to the target location.
Image RemovedImage Added | Image RemovedImage Added |
Next, we configure two File Operation Snaps to copy and move files from one folder to another folder. We use the first File Operation Snap to copy the sample file from abfss:///bigdataqa/Samplefile/ to abfss:///bigdataqa/samplefile_diff/).
...
The following Pipeline describes how the Snap functions as a standalone Snap in a Pipeline:
...
Download the Pipeline here or from the Downloads section below.
...
The exported Pipeline is available in the Downloads section below. More examples of operations are also available in the Downloads section - variousCasesOfFileOperations.pdf.
Typical Snap Configurations
...