自动上传到FTP服务器

我有两个本地用户需要扫描文件的办公室,然后让他们自动上传到他们的远程terminal服务器。 我可以将扫描软件设置为将文件保存到某个文件夹,但是我想自动将它们上传到TS,这样他们就不必离开会话来上传文件。 什么是一个好的文件夹观察员的XP,我可以用它来自动上传这些文件?

服务器是Win 2000,我不知道这是如何通常在Windows上完成的。 我知道我可以使用WinSCP作为脚本化的ftp客户端,但是我不知道通常用什么工具来查看文件夹的更改。 直觉说Powershell,但我不知道。 我的Python不起来,我不想安装在他们的电脑上,但这可能是最后的select。

—这是我发现的东西.–从今天开始的这个适时的线程在Debian Linux(一个新用户的超级链接)/ questions / 50127 / how-to-automatically-run-a-script -when-the-contents-of-a-directory-changes-in-lin这个线程是我在serverFault上find的最接近的,但是走错了路。 某种自动下载程序从FTP站点?

(META ps是否有删除标签的方法,有一个“上传”标签,应该是“上传”的,不需要复数)。

你可以使用WinSCP来执行这种自动上传。 它通常与SFTP或SCP一起使用,但它也支持普通的FTP(您的服务器实际上可以支持SFTP或SCP),并且可以通过其自动化脚本实现自动化:

WinSCP自动化指南

你正在寻找的具体命令是keepuptodate

http://winscp.net/eng/docs/script_commands

keepuptodate的问题是,它执行整个同步,这是慢的。 通过一些脚本,可以在修改后仅上载已更改的文件。

您可以使用FolderMon作为文件夹监视器。 然后处理它由Gawk输出,当然使用WinSCP上传。 整个过程可以通过简单的批处理脚本来控制:

REM本地目录(recursion)。 REM%CD% – 当前工作目录。 必须以'\'结尾。 设置“localPath =%CD%\”

 REM Remote directory, must end with '/' set "remotePath=/some/remote/directory" REM Name of the stored session in WinSCP set "[email protected]" 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; }" 

当然,你需要这个gawk脚本( autoupload.awk ):BEGIN { autoupload.awk来修复foldermon中的bug(feature?)。 #保存文件时,foldermon会在同一秒内报告两次更改。 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" } } } END { # Disconnect. print "close" print "exit" } 

你可以从这里下载zip文件。

我在使用Strix提供的自动上传脚本时遇到了一些问题,为了与Sublime Text 3一起工作(不确定Sublime Text 2将以同样的方式工作),必须稍微修改它。

如果您的脚本无法正常工作或上传空白(因此无法使用),请使用此修改后的版本replaceautoupload.awk的中间function:

  { if (match ($0, /^([:0-9]*) File modified: (.*)$/, matchRow)) { # File changed. time = matchRow[1] file = matchRow[2] # Sublime Text 2/3 creates several files and appends some temporary characters after the original file name like this: myfile~RF34be688.TMP. # The original version of this program didn't handle this correctly and uploaded everything to the server # until you killed the script # This if statement below handles this by matching for only the lines that have the ~ (tilde chracter) if ( match (file,/~/) ) { tildePOS = match (matchRow[2],/~/) file = substr(matchRow[2], 1, tildePOS - 1) 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" } } } } 

希望这可以帮助别人!