[Note from Pinal]: This is a new episode of Notes from the Field series. Every time I give an introductory note, however, this time there is no need of intro note. This note is from Andy and as we all know he is amazing person when we have to understand the fundamentals. He has written this blog post with such an interesting way that you must read it to understand the very basic of the file system task.
Many data integration scenarios involve reading data stored in flat files or performing extracts from a relational (or legacy) system into flat files. Learning how to configure and use the SQL Server Integration Services (SSIS) File System Task will support your efforts when loading data to and from flat files. Remember: SSIS is a software development platform. With “SQL Server” included in the name, it is easy for people to confuse SSIS as a database tool or accessory, but Control Flow Tasks put that confusion to rest.
SSIS provides several Control Flow tasks. Here is a list that provides a good approximation of which tasks I use most, from most-used to least-used:
- Execute SQL Task
- Data Flow Task
- Script Task
- Execute Package Task
- File System Task
- Execute Process Task
In this article I provide a basic example of configuring the SSIS File System Task, shown in Figure 1:
Figure 1: SSIS File System Task
The File System Task provides one way to implement an SSIS Design Pattern for source file archival. When you first open the File System Task Editor, you will note several properties in the property grid. Whenever you see an Operation property in an SSIS task editor, know that that property drives the other property selections. Options for the Operation property of the SSIS File System Task are shown in Figure 2:
Figure 2: SSIS File System Task Operation Property Options
The Operation options are:
- Copy directory
- Copy file (default)
- Create directory
- Delete directory
- Delete directory content
- Delete file
- Move directory
- Move file
- Rename file
- Set Attributes
I stated the Operation property drives the other property selections. Take a look at the File System Task Editor when I change the Operation option from “Copy file” (Figure 2) to “Delete file” as shown in Figure 3:
Figure 3: The File System Task Editor with the “Delete file” Operation Selected
See? There are less properties required for the “Delete file” operation. The available properties are even more different for the “Set Attributes” operation, shown in Figure 4:
Figure 4: The File System Task Editor with the “Set Attributes” Operation Selected
The Operation property changes the editable properties, exposing some and hiding others. With flexibility come complexity. Even though the File System Task is complex, I’ve found the task is stable and extremely useful. Let’s look at a practical example; using the File System Task to archive a flat file.
To begin configuring the SSIS File System Task for file archival, select the “Move file” operation as shown in Figure 5:
Figure 5: SSIS File System Task with the “Move file” Operation Selected
Using the IsSourcePathVariable and IsDestinationPathVariable properties extends the flexibility of the File System Task and further changes the list of available properties in the property grid, as shown in Figure 6:
Figure 6: Opting to Use Variables for Source and Destination Paths
Note the SourceConnection and DestinationConnection properties are hidden and the SourceVariable and DestinationVariable properties are available in their place. For the sake of simplicity, we’re not going to use SSIS Variables to define the source and destination paths in this article. Reset the IsSourcePathVariable and IsDestinationPathVariable properties to False. Click the SourceConnection property dropdown, and click “<New connection…>” as shown in Figure 7:
Figure 7: Selecting a New Connection for the SSIS File System Task SourceConnection Property
The File Connection Manager Editor displays with the “Usage type” property set to “Existing file” as shown in Figure 8:
Figure 8: File Connection Manager Editor
Click the “Browse…” button and select a flat file you wish to move, as shown in Figure 9:
Figure 9: Selecting the Source File
Once the File Connection Manager Editor is configured, it should appear similar to that shown in Figure 10:
Figure 10: A Configured File Connection Manager Editor
Click the OK button to close the File Connection Manager Editor. Next, click the DestinationConnection property in the SSIS File System Task Editor. As with the SourceConnection property, click the dropdown and select “<New connection…>”. When the File Connection Manager Editor displays, select the “Existing folder” Usage type, as shown in Figure 11:
Figure 11: Configuring the Destination File Connection Manager
Note the warning at the bottom of the File Connection Manager Editor window: “Folder name must be specified.” Click the “Browse…” button and navigate to the directory where you wish to archive the source file as shown in Figure 12:
Figure 12: Configuring the Location of the DestinationConnection File Connection
Click the OK button in the “Browse For Folder” dialog to return to the File Connection Manager Editor, as shown in Figure 13:
Figure 13: A File Connection Manager Configured for the DestinationConnection Property
Click the OK button to close the File Connection Manager Editor and return to the File System Task Editor, as shown in Figure 14:
Figure 14: An SSIS File System Task Configured to Archive a File
The SSIS File System Task is now configured to archive a file. Let’s test it! Click the OK button to close the File System Task Editor. Press the F5 key or select SSIS->Start Debugging to test your work. My result is shown in Figure 15:
Figure 15: Successful Test Execution of the SSIS File System Task
Viewing the source and destination directories, we see the file was successfully moved – shown in Figure 16:
Figure 16: The File, Moved!
One tricky part when configuring the SSIS File System Task to move a file is realizing that you need to select the actual file for the source and the directory for the destination.
As I stated earlier, the SSIS File System Task is powerful, flexible, and robust. This article has demonstrated one way you can use the File System Task to archive files. Archiving files after loading the data they contain is a common practice in data integration.
If you want to get started with SSIS with the help of experts, read more over at Fix Your SQL Server.
Reference: Pinal Dave (https://blog.sqlauthority.com)
8 Comments. Leave new
So that’s what Andy was working on at the airport last night ;-)
Thank you Andy for the nice article and thank you Pinal for showing Andy to us !
your welcome ksathish1.
can you give one example for copy and Move directory
Awesome!
Thanks for educating the community and appreciate your volunteer-ship.
Please please keep educating others and make the world beautiful!
I am sure you can answer Ramesh’s question.
How do you solve for dynamic name flat files? What is the best strategy when you need to process multiple flat files?
Thank you Andy. Nice article.