Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have two users local to an office that need to scan documents then have them automatically upload to their remote Terminal Server. I can set the scanning software to save the files to a certain folder, but I would like to automatically upload them to the TS so they don't have to leave their session to upload the files. What is a good folder watcher for xp that I can use to automatically upload these files?

The server is Win 2000 and I am not sure how this is generally done on windows. I understand I can use WinSCP as a scriptable ftp client, but I don't know what tool is usually used for watching a folder for changes. Intuition says Powershell, but I don't know. My Python isn't up to snuff and I don't want to install it on their computers, but that might be a last option.

---This is what I found looking around.--- This timely thread from today shows a good utility on Debian Linux (one hyper link for new users)/questions/50127/how-to-automatically-run-a-script-when-the-contents-of-a-directory-changes-in-lin And this thread is the closest I found on serverFault, but goes the wrong way. http://serverfault.com/questions/18889/some-kind-of-auto-downloader-from-an-ftp-site

(META ps Is there a way to delete tags. There is one tag for 'uploads' that should probably be 'upload'. No need for plurals.)

share|improve this question

2 Answers 2

up vote 3 down vote accepted

You can use WinSCP to perform this kind of automatic upload. It's normally used with SFTP or SCP but it supports plain FTP as well (your server may actually be capable of SFTP or SCP) and this can be automated with their automation scripting:

WinSCP Automation Guide

The specific command you're looking for is keepuptodate:


share|improve this answer
So, what you're telling me is RTFM :) thanks for holding your tongue. Maybe I should have read the whole WinSCP site before I began looking for a watching program. I'll figure this out tomorrow and give you the check now. Thank you very much. –  Radix Aug 5 '09 at 3:46

The problem with keepuptodate is, that it perform whole synchronisation, which is slow. With a little bit of scripting it is possible to upload only changed files after they are modified.

You can use FolderMon as a folder watcher. Then process it's output by Gawk and of course use WinSCP for uploading. The whole process can be controlled by simple batch script:

REM Local directory (recursive). REM %CD% - current working directory. Must end with '\'. set "localPath=%CD%\"

REM Remote directory, must end with '/'
set "remotePath=/some/remote/directory"

REM Name of the stored session in WinSCP
set "session=stored@session.com"

REM --------------------------------------------------------

REM Escape local path - replace '\' with '\\'.
set "escapedLocalPath=%localPath:\=\\%"

foldermon -lastwrite -subdirs %localPath% | ^
gawk -f autoupload.awk -v "localPath=%escapedLocalPath%" -v "remotePath=%remotePath%" -v "session=%session%" | ^
winscp.com /console | ^
gawk "{ if (!/#aaaaaaaaaaaaaaaaa/) print; }"

And of course you need that gawk script (autoupload.awk): BEGIN { # Variable to fix bug (feature?) in foldermon. # When file is saved, foldermon reports two changes in the same second. lastLocalFile = "" lastTime = ""

    # Init and connect
    print "#remotePath=", remotePath
    print "#localPath=", localPath
    print "#session=", session

    print "option batch abort"
    print "option confirm off"
    print "open " session
    print "option transfer binary"
    #print "cd " remotePath

    # Flush AWK buffer.
    for (i=0; i<41; i++)
        print "#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    if (match ($0, /^([:0-9]*) File modified: (.*)$/, matchRow)) {
        # File changed.

        time = matchRow[1]
        file = matchRow[2]
        localFile = localPath file

        # Don't upload same file twice immediately.
        if (localFile!=lastLocalFile || lastTime!=time) {
            lastLocalFile = localFile
            lastTime = time

            # Extract subdirectory from change report and convert '\' to '/'.
            match (file, /^((.*[\\])*).*$/, matchPath);
            path = matchPath[1]
            gsub(/\\/, "/", path)

            # Change remote dir and upload.
            #print "cd " remotePath path
            print "put", localFile, remotePath path

            # Flush AWK buffer.
            for (i=0; i<41; i++)
                print "#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    # Disconnect.
    print "close"
    print "exit"

You can download zip file with everything included from here.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.