How to avoid SSIS FTP task from failing when there are no files to download?

后端 未结 12 818
时光取名叫无心
时光取名叫无心 2020-12-01 06:42

I\'m using SQL Server 2005, and creating ftp tasks within SSIS.

Sometimes there will be files to ftp over, sometimes not. If there are no files, I don\'t want the

12条回答
  •  [愿得一人]
    2020-12-01 07:23

    (I can't accept my own answer, but this was the solution that worked for me.)

    It may not be the best solution, but this works.

    I use a script task, and have a bunch of variables for the ftp connection information, and source and destination directories. (Because, we'll be changing the server this is run on, and it will be easier to change in a config package.)

    I create a text file on the fly, and write the ftp commands to it:

        Dim ftpStream As StreamWriter = ftpFile.CreateText()
        ftpStream.WriteLine(ftpUser)
        ftpStream.WriteLine(ftpPassword)
        ftpStream.WriteLine("prompt off")
        ftpStream.WriteLine("binary")
        ftpStream.WriteLine("cd " & ftpDestDir)
        ftpStream.WriteLine("mput " & ftpSourceDir)
        ftpStream.WriteLine("quit 130")
        ftpStream.Close()
    

    Then, after giving it enough time to really close, I start a process to do the ftp command:

        ftpParameters = "-s:" & ftpParameterLoc & ftpParameterFile & " " & ftpServer
        proc = System.Diagnostics.Process.Start("ftp", ftpParameters)
    

    Then, after giving it some more time for the ftp process to run, I delete the temporary ftp file (that has connection information in it!).

    If files don't exist in the source directory (the variable has the \\drive\dir\*.* mapping), then there is no error. If some other error happens, the task still fails, as it should.

    I'm new to SSIS, and this may be a kludge. But it works for now. I guess I asked for the best way, and I'll certainly not claim that this is it.

    As I pointed out, I have no way of knowing what the files are named, or even if there are any files there at all. If they are there, I want to get them.

提交回复
热议问题