在Script Task
中,我正在尝试从联网位置检索文件,并将FTP
该文件检索到非现场位置
FTP Connection
并测试了它是否已设置并正常工作创建了三个变量
创建了Script Task
并添加了vb代码......
'Get instance of the connection manager.
Dim cm As ConnectionManager = Dts.Connections("FTP Connection Manager")
Dim remotePath As String = Dts.Variables("FTPFilePath").Value.ToString
'create the FTP object that sends the files and pass it the connection
'created above.
Dim ftp As FtpClientConnection = New FtpClientConnection
(cm.AcquireConnection(Nothing))
'Connect to the ftp server
ftp.Connect()
'Set the path on the FTP server where dropping files
'ftp.SetWorkingDirectory("/Prequalify") 'set the remote directory
Dim files(0) As String
files(0) = Dts.Variables("FTPFileName").Value.ToString 'eg. File1.trg
'Send File
ftp.SendFiles(files, remotePath, True, True)
' Close the ftp connection
ftp.Close()
'Dts.Events.FireInformation(0, context, "File " + fileToGet
' + " retrieved successfully.", Nothing, Nothing, True)
Dts.TaskResult = Dts.Results.Success
错误:在集合中找不到该元素。当您尝试在执行包期间从容器上的集合中检索元素并且该元素不存在时,会发生此错误。
所以我已经注释掉了,发现错误是在检索变量值时产生的,但我不知道这里有什么不正确
Dim remotePath As String = Dts.Variables("FTPFilePath").Value.ToString
我尝试了多个变量检索,但都得到了同样的错误。有人看错了吗?
答案 0 :(得分:15)
两件事:
Dts.Variables["User::RemotePath"].Value