• Wscript FTP applicaiton (VBA )

    Author
    Topic
    #431686

    (Edited by HansV to make URL clickable – see Help 19)

    My Access XP application needs to send and receive files from an FTP server each day. I found this code
    on a website (thanks to http://www.sqlservercentral.com/columnists…tomatetasks.asp%5B/url%5D) and
    attempted to modify it to meet my needs. However the error message:
    “Compile Error: Variable Not Defined” appears when I attempt to run it. The variable in question is Wscript on
    the line

    Set objShell = Wscript.CreateObject(“WScript.Shell”)
    I tried to set a reference to Microsoft WMI Scripting but it did not help.

    Any ideas what is going on here?

    ”””””””””””””””””””””””””””””””””””””””””””””’
    Sub GetMyFiles()
    Dim objFSO, objMyFile, objShell, strFTPScriptFileName, strFile2Get
    Dim strLocalFolderName, strFTPServerName, strLoginID
    Dim strPassword, strFTPServerFolder

    ‘Customize code here to fit your needs
    strLocalFolderName = “C:temp”
    strFTPServerName = “ftp://somesite.net/”
    strLoginID = “abcftp”
    strPassword = “abc”
    strFTPServerFolder = “some_FTP_Folder”

    strFile2Get = “TestDownload.txt”

    ‘The following code generates the file name on the FTP server you want to get
    ‘strFile2Get = “Data” & strFile2Get & “.csv”

    ‘The follow lines of code generate the FTP script file on the fly,
    ‘because the get file name changes every day

    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

    ‘The following code executes the FTP script. It creates a Shell
    ‘object and run FTP program on top of it.

    Set objShell = Wscript.CreateObject(“WScript.Shell”) ‘THIS IS THE LINE THAT ALWAYS BOMBS!!!’

    objShell.Run (“ftp -s:” & Chr(34) & strFTPScriptFileName & Chr(34))
    Set objShell = Nothing

    Thanks,

    Viewing 0 reply threads
    Author
    Replies
    • #1010915

      Try changing the line to

      Set objShell = CreateObject(“WScript.Shell”)

      • #1010917

        Thanks Hans. Can you tell me why this change worked where the original line of code did not?

        • #1010919

          CreateObject is a general VBA function, it can be used without prefixing it with anything. You can’t use WScript to create a WScript object.

        • #1010950

          Your code example is from a different context: a VBScript file executing against the Windows Script Host. Just as the VBA/Office environment is aware of certain top level objects by default and not others, so with VBScript.

    Viewing 0 reply threads
    Reply To: Wscript FTP applicaiton (VBA )

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: