SQLDTS FTP and question after file retrieval -
07-13-2005
, 03:59 PM
I have a job where I ftp a text file from a site, and write it out to a
folder on my server. In the step, I plan to delete the input file once
it's transferred.
I have a script that's supposed to grab it, set a global variable and
proceed with the job.
If the input file is out on the ftp server, it works fine. However, if
there's no input file, the job below stops because there's nothing in
the folder where I'm looking for the file.
I had set up the workflow to go one place if true, and another if false,
but am having problems because the workflow has another workflow
downstream from this point, where it makes a decision as to whether I've
already processed the file.
Basically, I want to go out & grab the file from the ftp site (I am
using the SQLDTS one 1.1.12, set on a filter to grab only the files with
a particular extension), and then delete the input once it's been ftp'd.
Then, I want to know if I did get a file, and if so, continue normally
(and make a determination if I've already got the file, or process it
and write out a note to a table). If I didn't get a file, I want to
just skip over everything, and not do anything more.
The script below dies if there's no input file.
---begin script
'************************************************* *********************
' Visual Basic ActiveX Script
'************************************************* ***********************
Function Main()
Dim fso, folder, file, filecollection
Dim oFSO, sFileName
Set fso=CreateObject("Scripting.FileSystemObject")
Set folder=fso.GetFolder("\\myserver\sfa\coop")
Set filecollection=folder.Files
For each file in filecollection
DTSGlobalVariables("ImportFileName").Value=file.Na me
Exit For
Next
DTSGlobalVariables("ImportFilePathName").Value="\\ myserver\sfa\coop\" &
DTSGlobalVariables("ImportFileName").Value
' Get the name of the file from the global variable
"ImportFileName"
sFilename = DTSGlobalVariables("ImportFilePathName").Value
Set oFSO = CreateObject("Scripting.FileSystemObject")
'msgbox sFilename
' Check for file and return appropriate result
If oFSO.FileExists(sFilename) Then
DTSGlobalVariables("CoopFileDate1").value =
left(DTSGlobalVariables("ImportFileName").Value,8)
Main = DTSStepScriptResult_ExecuteTask
Else
Main = DTSStepScriptResult_DontExecuteTask
End If
Set oFSO = Nothing
End Function
-- end script
I cannot use the script below, because of the workflow that exists
downstream from it.
--begin
' 218 (SetupPath)
Option Explicit
' /* Change these constants to suit your package */
' Name of the global variabled used to decide the path
' This example requires a boolean
Const DTSPath_GlobalVariable_Name = "ExecuteNoFilePath"
' Name of the first Step in the "True" Path
Const DTSPath_True_First_Step = "DTSStep_DTSActiveScriptTask_10"
' Name of the last Step in the "True" Path
Const DTSPath_True_Last_Step = "DTSStep_DTSActiveScriptTask_10"
' Name of the first Step in the "False" Path
Const DTSPath_False_First_Step = "DTSStep_DTSActiveScriptTask_11"
' Name of the last Step in the "False" Path
Const DTSPath_False_Last_Step = "DTSStep_DTSActiveScriptTask_11"
' Name of OR Step
Const DTSPath_OR_Step = "DTSStep_DTSActiveScriptTask_6"
Function Main()
Dim oPkg, oConstraints, oConstraint
' Get reference to the package
Set oPkg = DTSGlobalVariables.Parent
' Diable the workflow path we are not using
oPkg.Steps(DTSPath_True_First_Step).DisableStep = _
Not DTSGlobalVariables(DTSPath_GlobalVariable_Name).Va lue
oPkg.Steps(DTSPath_False_First_Step).DisableStep = _
DTSGlobalVariables(DTSPath_GlobalVariable_Name).Va lue
' Get reference to the PrecedenceConstraints collection,
' for which we need to simulate the OR
Set oConstraints = oPkg.Steps(DTSPath_OR_Step).PrecedenceConstraints
If DTSGlobalVariables("ExecuteNoFilePath").Value Then
' Set our True path OR
Set oConstraint = GetConstraint(oConstraints, DTSPath_True_Last_Step)
oConstraint.PrecedenceBasis = DTSStepPrecedenceBasis_ExecResult
oConstraint.Value = DTSStepExecResult_Success
Set oConstraint = GetConstraint(oConstraints, DTSPath_False_Last_Step)
oConstraint.PrecedenceBasis = DTSStepPrecedenceBasis_ExecStatus
oConstraint.Value = DTSStepExecStat_Inactive Or DTSStepExecStat_Waiting
oPkg.Steps(DTSPath_False_Last_Step).ExecutionStatu s = _
DTSStepExecStat_Inactive Or DTSStepExecStat_Waiting
Else
' Set our False path OR
Set oConstraint = GetConstraint(oConstraints, DTSPath_False_Last_Step)
oConstraint.PrecedenceBasis = DTSStepPrecedenceBasis_ExecResult
oConstraint.Value = DTSStepExecResult_Success
Set oConstraint = GetConstraint(oConstraints, DTSPath_True_Last_Step)
oConstraint.PrecedenceBasis = DTSStepPrecedenceBasis_ExecStatus
oConstraint.Value = DTSStepExecStat_Inactive Or DTSStepExecStat_Waiting
oPkg.Steps(DTSPath_True_Last_Step).ExecutionStatus = _
DTSStepExecStat_Inactive Or DTSStepExecStat_Waiting
End If
Set oPkg = Nothing
Set oConstraints = Nothing
Set oConstraint = Nothing
Main = DTSTaskExecResult_Success
End Function
Function GetConstraint(oConstraints, sStepName)
' Get Constraint by Source Step Name
Dim oConstraint
For Each oConstraint In oConstraints
If oConstraint.StepName = sStepName Then
Set GetConstraint = oConstraint
Exit For
End If
Next
End Function
--end
Any idea as to how to do this?
BC |