Friday, March 30, 2012

If file exist, FTP file

Within a SQL Server Job, I am using the following vbscript to connect to a
FTP server and FTP a file:
strLocalFolderName = "My Folder Name where we put the file to be FTPed"
strFTPServerName = "FTP Server Name"
strLoginID = "FTP Server Login ID"
strPassword = "FTP Login ID Password"
strFTPServerFolder = "Folder Name on FTP server where the file resides"
strFile2Get = "This file"
strFTPScriptFileName = strLocalFolderName & "\FTPScript.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If (objFSO.FileExists(strFTPScriptFileName)) Then
objFSO.DeleteFile (strFTPScriptFileName)
End If
Set objMyFile = objFSO.CreateTextFile(strFTPScriptFileName, True)
objMyFile.WriteLine ("open " & strFTPServerName)
objMyFile.WriteLine (strLoginID)
objMyFile.WriteLine (strPassword)
objMyFile.WriteLine ("cd " & strFTPServerFolder)
objMyFile.WriteLine ("ascii")
objMyFile.WriteLine ("lcd " & strLocalFolderName)
objMyFile.WriteLine ("get " & strFile2Get)
objMyFile.WriteLine ("bye")
objMyFile.Close
Set objFSO = Nothing
Set objMyFile = Nothing
Before I FTP the file, I need to check to see if that file exist. What is
the best way for me to check to see if that file exist? Or how can I
capture the code from the FTP command if it can't find the file?Oops, I left this out of my code example. Add this to the end of the code:
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run ("ftp -s:" & chr(34) & strFTPScriptFileName & chr(34))
Set objShell = Nothing
"David" wrote:

> Within a SQL Server Job, I am using the following vbscript to connect to a
> FTP server and FTP a file:
> strLocalFolderName = "My Folder Name where we put the file to be FTPed"
> strFTPServerName = "FTP Server Name"
> strLoginID = "FTP Server Login ID"
> strPassword = "FTP Login ID Password"
> strFTPServerFolder = "Folder Name on FTP server where the file resides"
> strFile2Get = "This file"
> strFTPScriptFileName = strLocalFolderName & "\FTPScript.txt"
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> If (objFSO.FileExists(strFTPScriptFileName)) Then
> objFSO.DeleteFile (strFTPScriptFileName)
> End If
> Set objMyFile = objFSO.CreateTextFile(strFTPScriptFileName, True)
> objMyFile.WriteLine ("open " & strFTPServerName)
> objMyFile.WriteLine (strLoginID)
> objMyFile.WriteLine (strPassword)
> objMyFile.WriteLine ("cd " & strFTPServerFolder)
> objMyFile.WriteLine ("ascii")
> objMyFile.WriteLine ("lcd " & strLocalFolderName)
> objMyFile.WriteLine ("get " & strFile2Get)
> objMyFile.WriteLine ("bye")
> objMyFile.Close
> Set objFSO = Nothing
> Set objMyFile = Nothing
> Before I FTP the file, I need to check to see if that file exist. What
is
> the best way for me to check to see if that file exist? Or how can I
> capture the code from the FTP command if it can't find the file?

No comments:

Post a Comment