Upload/FTP Batch File - Modified Only

Posted on 2010-01-08
Last Modified: 2013-12-09
We have a batch file scheduled to run daily, which uploads several files to our web server. Recently, weve had a request for a much higher volume of files to be added to the upload list, thus, I would like to be able to upload only files that were modified since the last run.

Here are the contents of the batch file:

%windir%\system32\ftp.exe -s:sendRcv.txt
@echo off
Here are the contents of sendRcv.txt:

cd public_html
lcd d:\PHA\fmExports
put whatever
Question by:rvfowler2
    LVL 38

    Accepted Solution

    Paste the script below into a text file with a .vbs extension.  Customize the value of the strLocalFolder variable on line 1 with the location of the folder containing the files to be uploaded.  Customize the values of the FTP variables on lines 4-7 as appropriate.

    Running the script will generate an FTP script file containing commands to upload the files which have been modified since the last time the script was run.  Once you have tested it successfully and are certain it will do what you intend, remove the apostrophe from line 48 to call the FTP script and upload the files.

    strLocalFolder = "d:\PHA\fmExports"
    strScript = "sendRcv.txt"
    strFTPServer = ""
    strFTPUserName = "username"
    strFTPPassword = "password"
    strFTPRemoteFolder = "public_html"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objLocalFolder = objFSO.GetFolder(strLocalFolder)
    If objFSO.FileExists(strScript) Then
        Set objScript = objFSO.GetFile(strScript)
        dtmLastRun = objScript.DateLastModified
        dtmLastRun = #1/1/1900#
    End If
    Set objScript = objFSO.CreateTextFile(strScript, True)
    intCount = 0
    For Each objFile In objLocalFolder.Files
        If objFile.DateLastModified > dtmLastRun Then
            ReDim Preserve arrUploads(intCount)
            arrUploads(intCount) = objFile.Name
            intCount = intCount + 1
        End If
    If intCount > 0 Then
        objScript.WriteLine "open " & strFTPServer
        objScript.WriteLine strFTPUserName
        objScript.WriteLine strFTPPassword
        objScript.WriteLine "cd " & Chr(34) & strFTPRemoteFolder & Chr(34)
        objScript.WriteLine "binary"
        objScript.WriteLine "hash"
        objScript.WriteLine "lcd " & Chr(34) & strLocalFolder & Chr(34)
        For Each strUpload In arrUploads
            objScript.WriteLine "put " & Chr(34) & strUpload & Chr(34)
        objScript.WriteLine "bye"
        Set objShell = WScript.CreateObject("WScript.Shell")
        'objShell.Run "ftp -s:" & Chr(34) & strScript & Chr(34)
    End If

    Open in new window

    LVL 2

    Author Comment

    Lookis promising.  Will try it on Monday.
    LVL 2

    Author Comment

    Still working on it.  Our server went down yesterday.
    LVL 2

    Author Comment

    Worked fairly well on Friday, just working out a couple of kinks.  If we can't solve it, we will ask a follow up question on Monday.
    LVL 2

    Author Closing Comment

    Worked 99% and we worked out all the rest of the adjustments except having problems making the script create a log file.  Awarding the points anyway.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Hello, As I have seen there a lot of requests regarding monitoring and reporting for exchange 2007 / 2010 / 2013 I have decided to post some thoughts together and link to articles that have helped me. Of course a lot of information you can get…
    With the withdrawal of support for Windows Server 2003 this summer, many clients face the issue of moving away from their 2003 installs. There are a few options out there that many people/companies are selling. But the clients I have, haven't wanted…
    Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now