VBS ftp下载等待时间

时间:2016-06-21 11:04:40

标签: vbscript 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

如果我没有设置相应的等待时间,则在下载完成之前开始处理文件。因为我必须下载大文件,我需要为等待时间设置一个高值。如果下载量不是很大,那就等待太久了。

有没有办法等待下载完成,而不是任意和恒定的时间?

谢谢

1 个答案:

答案 0 :(得分:2)

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

Const ForWriting = 2
Set objFso = CreateObject("Scripting.FileSystemObject")
Set sessionFile = objFso.OpenTextFile("session.txt", ForWriting, vbTrue)
With sessionFile
    .WriteLine "open ftp://user:pass@xx.xx.xx.xx"
    .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
相关问题