Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 526
  • Last Modified:

Upload/FTP Batch File - Modified Only

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:

open ftp.xxx.com
cd public_html
lcd d:\PHA\fmExports
put whatever
  • 4
1 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 = "ftp.xxx.com"
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

rvfowler2Author Commented:
Lookis promising.  Will try it on Monday.
rvfowler2Author Commented:
Still working on it.  Our server went down yesterday.
rvfowler2Author Commented:
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.
rvfowler2Author Commented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now