Problem with Script task and FTP GetListing

  • Hi

    I'm struggling with a Script Task to FTP receive files.

    I my script I want to determine if a specified remote folder is empty or not.

    If it is not empty execute a ReceiveFiles() , otherwise set a package variable value to 0.

    However, if the remote folder is empty (no files) I get an error.

    My code looks as follows:

    Dim conM As ConnectionManager = Dts.Connections.Add("FTP")

    Dim strFolders As String(), FTPRemotePath As String

    Dim FTPTargetFolder As String

    Dim strFiles As String()

    Dim fileCount As Int32

    fileCount = 0

    Dim fileName As String, FTPServer As String, FTPUser As String, FTPPassword

    As String

    FTPServer = Dts.Variables("FTPServer").Value.ToString()

    FTPUser = Dts.Variables("FTPUser").Value.ToString()

    FTPPassword = Dts.Variables("FTPPassword").Value.ToString()

    'Set the properties like username & password

    conM.Properties("ServerName").SetValue(conM, FTPServer)

    conM.Properties("ServerUserName").SetValue(conM, FTPUser)

    conM.Properties("ServerPassword").SetValue(conM, FTPPassword)

    conM.Properties("ServerPort").SetValue(conM, "21")

    conM.Properties("Timeout").SetValue(conM, "0")

    conM.Properties("ChunkSize").SetValue(conM, "1000") '1000 kb

    conM.Properties("Retries").SetValue(conM, "5")

    FTPRemotePath = Dts.Variables("FTPRemotePath").Value.ToString()

    FTPTargetFolder = Dts.Variables("SourceFolder").Value.ToString()

    Dim ftp As FtpClientConnection = New

    FtpClientConnection(conM.AcquireConnection(Nothing))

    ''Connects to the ftp server

    http://ftp.Connect()

    http://ftp.SetWorkingDirectory(FTPRemotePath )

    http://ftp.GetListing(strFolders, strFiles)

    '-------------------------

    'If the folder specified in "FTPRemotePath" is empty

    'the following codeline produces an error: "Object reference not set to an instance of an object. "

    For Each fileName In strFiles

    If fileName.Contains("sc_ash_") Then

    fileCount = fileCount + 1

    End If

    Next

    It seems that the string array "strFiles" is no longer valid and I

    clueless on how to work around this issue.

    Appreciate any thoughts.

    --

    Thanks in advance

    Bodo

  • Check strFiles if it is NULL. It should be something like

    If Not strFiles Is Nothing Then

    ...

    ---
    SSIS Tasks Components Scripts Services | http://www.cozyroc.com/

  • Great, works perfect!

    Thanks a million!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply