2016-06-21 70 views
1

我在VBS中编写一个脚本,用于从FTP服务器下载文件并对其进行处理。我有这样一串代码工作正常:VBS ftp下载等待时间

path = evidenceFolder 
On Error Resume Next 
Const copyType = 16 

Set oShell = CreateObject("Shell.Application") 
Set objFSO = CreateObject("Scripting.FileSystemObject") 

'FTP Wait Time in ms 
waitTime = 3000000 

strFTP = "ftp://" & FTPUser & ":" & FTPPass & "@" & FTPHost & FTPDir & FTPRoute 
Set objFTP = oShell.NameSpace(strFTP) 

'Download all files in folder 
If objFSO.FolderExists(path) Then 
    'Entire folder 
    Set objFolder = oShell.NameSpace(path) 
    objFolder.CopyHere objFTP.Items, copyType 
End If 
If Err.Number <> 0 Then 
    Wscript.Echo "Error: " & Err.Description & " - " & Err.Number 
End If 
'Wait for upload 
Wscript.Sleep waitTime 

如果我不设置文件的适当等待时间的处理开始之前下载完成。由于我必须下载大文件,我需要为等待时间设置一个很高的值。如果下载量不是很大,它会一直等待很长时间。

有没有一种方法只是等待下载完成,而不是一个任意的和恒定的时间?

谢谢

回答

2

最后,我设法通过改变做FTP的方式来解决它。我已经下载了Winscp并将其用作命令行ftp客户端,因为windows客户端并未接受pastive模式,并且正在生成FW问题。

Const ForWriting = 2 
Set objFso = CreateObject("Scripting.FileSystemObject") 
Set sessionFile = objFso.OpenTextFile("session.txt", ForWriting, vbTrue) 
With sessionFile 
    .WriteLine "open ftp://user:[email protected]" 
    .WriteLine "cd " & FTPDir & FTPRoute 
    .WriteLine "get *.* " & destFolder & "\" 
    .WriteLine "exit" 
    .Close 
End With 
strFTP = "tools\winscp577\winscp.com /script=session.txt" 
Set WshShell = CreateObject("WScript.Shell") 
strFTP = WshShell.ExpandEnvironmentStrings(strFTP) 
WshShell.Run strFTP,, vbTrue 
objFso.DeleteFile "session.txt", vbTrue