Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 FTP Script Task

Author  Topic 

PeaceOut
Starting Member

1 Post

Posted - 2011-09-17 : 09:04:52
Hi All,
I have been trying to get this working for a few days without any success. Any help would be GREATLY appreicated. I got the velow script from http://microsoft-ssis.blogspot.com/2011/08/foreach-ftp-file-enumerator.html and when I run it am getting the error.

[Script Task] Error: Error: The element cannot be found in a collection. This error happens when you try to retrieve an element from a collection on a container during execution of the package and the element is not there.

I am using SSIS 2008. I have uploaded the package here - http://www.mediafire.com/file/mbz5251kcb585dh/Package.dtsx

And here is the script-

using System;

using System.Data;

using Microsoft.SqlServer.Dts.Runtime;

using System.Windows.Forms;



namespace ST_3d9a6892ec6c460baa223c7d1f50dce7.csproj

{

// #C Code

using System;

using System.Collections; // Added

using System.Data;

using System.Net;

using Microsoft.SqlServer.Dts.Runtime;

using System.Windows.Forms;





namespace ST_a7c37bdf198947d7b76aa3b4221436a8.csproj

{

[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]

public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase

{



#region VSTA generated code

enum ScriptResults

{

Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,

Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure

};

#endregion



public void Main()

{

try

{

// Get the ftp connection from the Connection Managers collection

ConnectionManager ftpServer = Dts.Connections["FTPConnection"];



// Create a FTP connection object and us the credentials of connection manager

FtpClientConnection myFtpConnection = new FtpClientConnection(ftpServer.AcquireConnection(null));



// Open the connection

myFtpConnection.Connect();



// Set work folder with the value of the variable

myFtpConnection.SetWorkingDirectory(Dts.Variables["FtpWorkingDirectory"].Value.ToString());



// Create StringArrays for filenames and folders

// The folderNames aren't used, but is mandatory

// for the next method.

String[] fileNames;

String[] folderNames;



// Get a directory listing and fill the StringArray variables

myFtpConnection.GetListing(out folderNames, out fileNames);



// C# Code

// Download all files at once. Don't forget to add the SSIS variable DownloadDirectory to the ReadOnlyVariables

myFtpConnection.ReceiveFiles(fileNames, Dts.Variables["DownloadDirectory"].Value.ToString(), true, false);



// Close connection

myFtpConnection.Close();



// Close Script Task, set result to success

Dts.TaskResult = (int)ScriptResults.Success;

}

catch (Exception ex)

{

// Fire error and set result to failure

Dts.Events.FireError(0, "Script Task", "Error: " + ex.Message, string.Empty, 0);

Dts.TaskResult = (int)ScriptResults.Failure;

}

}

}

}

}

   

- Advertisement -