我正在尝试通过ftp发送文件,然后检查进程是否成功完成,如果是,我将删除原始文件并仅保留在FTP上的目标文件夹中发送的文件.
我设法修补了连接到FTP并发送文件的脚本,但我不确定如何与FTP上的文件夹交叉检查原始文件夹,以便我可以确定副本是否成功.
这是通过FTP发送文件的代码,在测试中它成功发送所有文件,但我必须在删除之前检查
Set oShell = CreateObject("Shell.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
path = "D:\test\"
FTPUpload(path)
Sub FTPUpload(path)
On Error Resume Next
Const copyType = 16
'FTP Wait Time in ms
waitTime = 80000
FTPUser = "test"
FTPPass = "testtest"
FTPHost = "ftp.test.com"
FTPDir = "/htdocs/test/"
strFTP = "ftp://" & FTPUser & ":" & FTPPass & "@" & FTPHost & FTPDir
Set objFTP = oShell.NameSpace(strFTP)
'Upload single file
If objFSO.FileExists(path) Then
Set objFile = objFSO.getFile(path)
strParent = objFile.ParentFolder
Set objFolder = oShell.NameSpace(strParent)
Set objItem = objFolder.ParseName(objFile.Name)
Wscript.Echo "Uploading file " & objItem.Name & " to " & strFTP
objFTP.CopyHere objItem, copyType
End If
'Upload all files in folder
If objFSO.FolderExists(path) Then
'Entire folder
Set objFolder = oShell.NameSpace(path)
Wscript.Echo "Uploading folder " & path & " to " & strFTP
objFTP.CopyHere objFolder.Items, copyType
End If
If Err.Number <> 0 Then
Wscript.Echo "Error: " & Err.Description
End If
'Wait for upload
Wscript.Sleep waitTime
End Sub
Run Code Online (Sandbox Code Playgroud)
我将不胜感激任何帮助,谢谢.
不确定这是否是最佳方式,但您可以通过FTP命令获取文件列表,并将结果与您期望的结果进行比较.这是一个例子:
' Create the FTP command file...
With CreateObject("Scripting.FileSystemObject").CreateTextFile("c:\ftp.txt", True)
.WriteLine "USER test"
.WriteLine "testtest"
.WriteLine "ls /htdocs/test/"
.WriteLine "quit"
.Close
End With
' Run the command and capture its output...
With CreateObject("WScript.Shell")
.Run "%comspec% /c ftp -n -v -s:c:\ftp.txt ftp.test.com >c:\filelist.txt", 0, True
End With
Run Code Online (Sandbox Code Playgroud)
这将创建该文件c:\filelist.txt,然后您可以打开该文件并检查您上传的文件是否存在.当然,您可以在ls命令中添加其他参数以获取更详细的信息.例如,ls -l会告诉您更新的日期以及文件大小.
| 归档时间: |
|
| 查看次数: |
22978 次 |
| 最近记录: |