tags:

views:

595

answers:

1

k i think i have spent way to long on this one. So here is what i am doing. In a ScriptTask I am trying to retrieve a file from a networked location and FTP that file to an offsite location.

  • In SSIS i created the FTP Connection and tested that it is setup and works. Created Three Variables (because i tested this a million ways)
  • variable 1. FullPathName = \ftpservercsc\\\Filename.txt
  • variable 2 FTPFilePath = \ftpservercsc\\\
  • variable 3 FTPFileName = Filename.txt

  • Created a script Task and added the vb code as such

    '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
    
  • 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.

  • So i have commented out and found the error is generating on retrieving the variable value but i do not know what is incorrect here

    Dim remotePath As String = Dts.Variables("FTPFilePath").Value.ToString
    

I have tried multiple variable retrievals and all get the same error. Anyone see anything wrong?

+2  A: 

Two things:

  1. Make sure you config the Script Task to have Read Access to the variable. To do this right-click on the Script Task and select Edit. Click the ... under ReadOnlyVariables.
  2. Fully qualify your variables such as Dts.Variables["User::RemotePath"].Value
Nissan Fan
Excellent! That was exactly it. The script runs now however it doesnt actually copy the file over. I think this gave me a great start though. Thanks for the assistance.

related questions