我正在研究一个SSIS脚本,一切都通过Visual Studio很顺利,但是当我执行时我得到:
[FTP脚本任务]错误:错误:对象引用未设置为 对象的实例。
这是我正在运行的代码。我做错了什么?
public void Main()
{
try
{
// Get the ftp connection from the Connection Managers collection
ConnectionManager ftpServer = Dts.Connections["SFTP_Connection"];
// Create a FTP connection object and us the credentials of connection manager
FtpClientConnection SFTP_Connection = new FtpClientConnection(ftpServer.AcquireConnection(null));
// Open the connection
SFTP_Connection.Connect();
// Set work folder with the value of the variable
SFTP_Connection.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
SFTP_Connection.GetListing(out folderNames, out fileNames);
SFTP_Connection.ReceiveFiles(fileNames, "\\\\server\\e$\\INFORMATICA_INCOMING\\VERSADEX\\CAD\\work\\Test\\", false, false);
// Close connection
SFTP_Connection.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, "FTP Script Task", "Error: " + ex.Message, string.Empty, 0);
Dts.TaskResult = (int)ScriptResults.Failure;
}
}