3 Replies Latest reply on Nov 9, 2011 7:34 AM by maxotics

    [VBS] Upload file FTP

    GunIva

      Hi,

       

      On my Mac I used this line in js to upload files to my print shop

       


      var myCurlScrpt = 'set curlShlScrpt to "curl ftp://myProxy.local:8021 -T \\"{" & "' + gDonePdfArray.join() + '" & "}\\" -u xxxx@ftp1.vvv.se:zzzzz"\ndo shell script curlShlScrpt';



      app.doScript(myCurlScrpt,ScriptLanguage.applescriptLanguage);

       

      Now I need to o this on a win box. I suppose VBScript is the way to go, unfortunately I have never written a single line in VBS and an example how to do this would be much appreciated.

       

      Thanks

        • 1. Re: [VBS] Upload file FTP
          John Hawkinson Level 5

          This is not all that helpful, but:

           

          Your above script leverages the MacOS command-line tool "curl" to upload files to an ftp server. Windows does not ship with an analagous tool, unfortunately.

           

          You could download and install curl for Windows: http://curl.haxx.se/download.html, then you could use an analagous VBscript to construct a command-line to run curl. Otherwise, you'll have to find some other way to do it. You could script access to the command-line ftp client in VB, or perhaps find a VB library that supports ftp.

           

          Anyhow, hopefully that gives you a better idea what is going on...

          • 2. Re: [VBS] Upload file FTP
            GunIva Level 1

            Thanks, I was hoping for some kind of native support. I seems a little to complicated for me att the moment. I will have to do with the upload service on my print shops website.

            • 3. Re: [VBS] Upload file FTP
              maxotics

              TECHNIQUE using Windows Command/Dos .bat file.

               

              This is a technique for creating a .BAT file from a BAT file to.  I'm not modifying to your purpose, because I haven't worked with this in a while.

               

              @ECHO OFF

              :: Create the temporary script file

              > script.ftp ECHO username

              >>script.ftp ECHO mypassword

              >>script.ftp ECHO cd myremotedir

              >>script.ftp ECHO binary

              >>script.ftp ECHO prompt n

              >>script.ftp ECHO put C:\ff_Factory2007\MatchFunds\somefile.mdb

              >>script.ftp ECHO quit

               

               

              :: Use the temporary script for unattended FTP

              :: Note: depending on your OS version you may have to add a '-n' switch

               

               

              FTP -v -s:script.ftp ftp.fundexpenses.com

              :: For the paranoid: overwrite the temporary file before deleting it

              TYPE NUL >script.ftp

              DEL script.ftp

              GOTO End

              :End

               

              TECHNIQUE #2

               

              VBS.

               

              Option Explicit

              Dim objFSO, objMyFile, objShell, strFTPScriptFileName, strFile2Get

              Dim strLocalFolderName, strFTPServerName, strLoginID

              Dim strPassword, strFTPServerFolder

               

               

              'Customize code here to fit your needs

              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"

               

               

              'The following code converts date to the right format, YYYYMMDD

              strFile2Get = DatePart("yyyy",Date)

               

               

              If DatePart("m",Date) < 10 Then

                      strFile2Get = strFile2Get & "0"

              End If

               

               

              strFile2Get = strFile2Get & DatePart("m",Date)

               

               

              If DatePart("d",Date) < 10 Then

                      strFile2Get = strFile2Get & "0"

              End If

               

               

              strFile2Get = strFile2Get & DatePart("d",Date)

               

               

              '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" )

              objShell.Run ("ftp -s:" & chr(34) & strFTPScriptFileName & chr(34))

              Set objShell = Nothing

               

              If you need more help, I may not check forum, so email me at max [at] htgrp dot com