Learn more about SQL Server tools



solving sql server problems for millions of dbas and developers since 2006 join MSSQLTips for free SQL Server tips













































   Got a SQL tip?
            We want to know!

SQL Server Integration Services SSIS FTP Task for Data Exchange

MSSQLTips author Arshad Ali By:   |   Read Comments (13)   |   Related Tips: More > Integration Services Control Flow Transformations
Problem

An FTP (File Transfer Protocol) server is often used for data exchanges in many data integration scenarios. SSIS includes an FTP task to download and upload data files to and from an FTP location, but how does this work and how can we configure it for data file downloads and uploads?

Solution

When data integration system or ETL processes can't connect directly to the data source system, an FTP server can be used as a temporary storage location for data exchange. Source systems can upload data to an FTP server and then the data integration system can download the data from the FTP server and import the data into the database.

SSIS being one of the leading ETL tools in the market includes an FTP task for working with an FTP server.  Downloading data files from an FTP server to the local machine and other tasks can be used to import the data from the locally downloaded data files to the database/data warehouse. Not only does the FTP Task allow downloading of the data files, but there are a host of other operations that can be performed with this task as mentioned below:

 

Operation

Description
Send files Used for uploading files from the local machine to the FTP server 
Receive files  Used for downloading files from the FTP server to the local machine 
Create local directory  Used to create a folder on the local machine 
Create remote directory  Used to creates a folder on the FTP server 
Remove local directory  Used to delete a folder on the local machine 
Remove remote directory  Used to delete a folder on the FTP server 
Delete local files  Used to delete a file on the local machine 
Delete remote files  Used to delete a file on the FTP server 

Connecting to an FTP Server Using Windows Explorer

There are different ways to connect to an FTP Server for data verification and one of the easiest ways is to use Windows Explorer.  Just specify the FTP Server name with FTP protocol as shown below and hit <Enter>.

There are different ways to connect to FTP Server for data verification

This will bring up a screen as shown below. Here we need to specify the credentials to connect to the FTP Server or choose to log on anonymously if the FTP Server allows anonymous access.

specify the FTP Server name with FTP protocol

Next click on the Log On button to log onto the specified FTP Server with the specified credentials. Based on permissions, it will display folders and files similarly to what's shown below:

click on Log On button

Using the FTP Task in an SSIS Package

In order to connect to an FTP Server, we first need to create an FTP connection manager which encapsulates information needed to connect to the FTP Server and the FTP task that uses that information at run time to connect to the server. In order to create a FTP connection manager create a new package and right click on the Connection Managers pane on the bottom and then select FTP as the connection manager type from the dialog box as shown below:

right click on the Connection Managers pane on the bottom and then select FTP as connection manager type f

Clicking on the Add button on the above dialog box will bring up an FTP Connection Manager Editor to specify the different information which will be used to connect to the FTP Server. For example, the FTP Server name, port, credentials to connect to the FTP Server, etc...

Clicking on Add button on the above dialog box will bring up a FTP Connection Manager Editor

Now you can drag an FTP Task from the SSIS Toolbox to the control flow, which will look similar to this:

drag the FTP task from the SSIS Toolbox to the control panel

Double click on the FTP task to change its properties in the Editor. The editor has 3 pages.  On the General page we need to select the FTP connection manager that we created above for connecting to the FTP Server and then specify an appropriate name and description for the component as shown below:

Double click on the FTP task to change its properties in the Editor

On the FTP Transfer page, we first need to select the operation that we want to perform (more about these different operations can be found in the beginning of this tip) with this FTP task based on the Local Parameters and Remote Parameters options will appear or disappear. For example, when we select "Receive files" as the operation type then both Local Parameters and Remote Parameters options will appear, but if I select the "Create remote directory" option then only the Remote Parameters option will appear.

the FTP Transfer page of FTP Task Editor

For this example I want to download a specific file from the FTP Server so I will chose "Receive files" as the operation type and then specify the remote parameters like location and name of the file to be downloaded and the local parameters like local machine folder where the downloaded file will be saved. Here, I can either specify hard-coded values for these parameters or the values can come from SSIS package variables making this process more dynamic.

chose "Receive files" as the operation type

As you might have noticed, we can select only one operation type for each FTP task and if we want to perform multiple operations we need to use multiple FTP tasks, one for each operation. Now if I execute the package we can see the file from the FTP Server getting downloaded and written to the folder that we specified. After the file has been downloaded I can then use a data flow task to load data from the locally downloaded file to the database.

the values can come from SSIS package variables

Downloading Multiple Files using a Wild Card Character

In the above example, I simply downloaded one file from the FTP Server to the local machine. But what if I want to download or upload all the text files or all the XML files in one go. Well in that scenario, we can use a wild card character. For example, as you can see below I want to download all text files from the specified FTP Server location to the local machine and hence I specified "*.txt" for the file name.

Downloading multiple files with wild card character

Now the above specified wild card character will download all the text files to the local machine from the FTP Server. To load each of these files to the database I can use a ForEach Loop container in SSIS as shown below.

the above specified wild card character will download all the text files to the local machine from the FTP Server

We can use the ForEach Loop Container with a ForEach File Enumerator and process all the data files from the locally downloaded folder; in other words, process each data file one at a time in a loop.

use ForEach Loop Container with ForEach File Enumerator and process all the data files

The FTP Task in SSIS does not support SFTP (Secured FTP), but there is a task available at codeplex which can be used for this scenario. 

Next Steps


Last Update: 2/15/2013


About the author
MSSQLTips author Arshad Ali
Arshad Ali is a SQL and BI Developer focusing on Data Warehousing projects for Microsoft.

View all my tips


print tip Print  
Become a paid author





join MSSQLTips for free SQL Server tips     



Learn more about SQL Server tools
Post a comment or let the author know this tip helped you.

       All comments are reviewed, so stay on subject or we may delete your comment.

*Name   *Email Notify for updates



       Note: your email address is not published. Required fields are marked with an asterisk (*)


Get free SQL tips:

*Enter Code refresh code     



Monday, October 06, 2014 - 2:35:15 PM - Arif Hassan Read The Tip

How do you set up ssis ftp package into ssms job, I am getting error message, only way I can do is to use encrypted password. Is there any work around?


Tuesday, September 30, 2014 - 3:36:39 PM - Golam Kabir Read The Tip

This is a great tip for me - thanks Arshad.


Thursday, September 18, 2014 - 11:13:39 AM - MGaylard Read The Tip

Concise, clear and accurate instructions

 

Thank you


Tuesday, August 26, 2014 - 12:57:01 PM - Liz Read The Tip

I can't seem to get the FTP connection manager to save the password. How do I get the ftp password saved?


Tuesday, April 15, 2014 - 7:19:27 PM - Jay Patel Read The Tip

I am trying to ftp file(s) from and to AS400 using ssis 2005 sql server. The ssis runs successfully but files are not sending or receiving. Any suggestions.


Tuesday, March 18, 2014 - 1:51:06 PM - Matt Massey Read The Tip

Great write up! This really helped me out as today was my first time setting up an FTP Task. Thanks!


Thursday, February 13, 2014 - 2:21:38 PM - Ravi Ramaswamy Read The Tip

Arshad,

Nice one. Easy and simple

Thanks,
Ravi Ramaswamy
 


Thursday, July 25, 2013 - 5:17:18 AM - SQLDBA Read The Tip

I am using SSIS package.

FTP Task Editor=>

IsLocalPathVarible:- True
Local Varible :- User::Final

Operation :Send Files
ISTransferASCII :- False

Remote Parameter
IsRemotePathVarible :-False

REmote Path :- \Location
OverwriteFileAtDest :- YES

Final:\test20130724_230456_662000000.xls which having expression
"D:\\test"+Replace(Replace(Replace(Replace((DT_WSTR,50)(getdate()),"-","")," ","_"),":",""),".","_")+".xls"

But [Connection manager "FTP Connection Manager"] Error: An error occurred in the requested FTP operation. Detailed error description: The filename, directory name, or volume label syntax is incorrect. .
e SSMS formatting.


Friday, June 07, 2013 - 1:44:08 PM - hjump51 Read The Tip

Steps to connect to SFTP within SSIS using BIDS.

 

1) link to setup SFTP task in SSIS  

http://ssissftp.codeplex.com/documentation

 

2) drag and drop for Windows 7 of SFTP dll

http://geekswithblogs.net/NibblesAndBits/archive/2012/04/09/adding-a-dll-to-the-gac-in-windows-7.aspx

 
 

 


Wednesday, June 05, 2013 - 12:44:04 PM - Mario Read The Tip

Hi,

Greate article, I was wonder if is possible to connect to a SFTP Server using FTP Task?

Thanks


Sunday, May 12, 2013 - 10:07:03 AM - Arshad Ali Read The Tip

Hi Yang, good to know it was helpful to you, thanks for your feedback.

 

Hi Chandu, yes you can use wildcard characters to download or upload files with specific naming pattern.


Saturday, May 11, 2013 - 10:59:23 AM - Yang Read The Tip

Dear Arshad,

It is really helpful!

Even yesterday I was struggling with the FTP file downloading and loading into database. Now it is all solved with your  article!

Thanks!

Yang


Wednesday, May 01, 2013 - 6:51:20 PM - chandu Read The Tip

Arshad,

 

Is it possible to place a dynamic criteria  for wildcharecters  for receiving files from a  ftp folder ,like a  specific date based expression criteria such as last  day of evefry month file from a list of files with date stamp.

 

 

Many Thanks

Chandu




 
Sponsor Information







Copyright (c) 2006-2014 Edgewood Solutions, LLC All rights reserved
privacy | disclaimer | copyright | advertise | about
authors | contribute | feedback | giveaways | free t-shirt | user groups | community | events | first timer?
Some names and products listed are the registered trademarks of their respective owners.