Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

SSIS FTP: Use same connection for multiple file transfers - error: There is already a task associated with this session

$
0
0

Hi,

I have an SSIS package that iterates over files using a foreach loop and uploads each file using a FTP connection object from the connection manager. That works quite well. However, I have noticed that for each file, a new FTP connection is established. To avoid that additional overhead, I would like to use the same FTP connection.

To do so, I have set up a script component that opens the FTP connection and stores it in a variable. In my foreach loop, I use a script component to upload a file through this connection. After the foreach loop, I close the connection in another script task.

When I run this package, the connection is established and the first file is uploaded. For the second file however, I receive an error saying that there is already a task associated with this FTP session.

Is there a way to overcome this, or do I really need to close and re-open a new connection for every file?

Thanks,

Roland

Here is the code excerpts of my script components in case someone is interested:

Script that opens the connection and stores it in a variable:

ConnectionManager connFTP = Dts.Connections["MyFTPConnection"];
FtpClientConnection ftp = new FtpClientConnection(connFTP.AcquireConnection(null));
ftp.Connect();
Dts.Variables["User::FTPConnection0"].Value = new object[] { ftp };
connFTP.Dispose();
Dts.TaskResult = (int)ScriptResults.Success;

Script inside foreach loop:

FtpClientConnection ftp = (FtpClientConnection)(((object[])Dts.Variables["User::FTPConnection0"].Value)[0]);
ftp.SendFiles(new string[] { Convert.ToString(Dts.Variables["User::FileName"].Value) }, "/", true, false);

Script after foreach-loop to close connection:

FtpClientConnection ftp = (FtpClientConnection)((object[])Dts.Variables["User::FTPConnection0"].Value)[0];
ftp.Close();
Dts.TaskResult = (int)ScriptResults.Success;


Viewing all articles
Browse latest Browse all 24688

Trending Articles