我有一个vbscript文件,如下所示:
Set oShell = CreateObject("Shell.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSB = CreateObject("System.Text.StringBuilder")
yesterday = DateAdd("d", -1, Date)
folderName = sprintf("{0:yyyyMMdd}", Array(yesterday)) & ".opentrades"
fullPath = "C:\test\" & folderName
Call FTPUpload(fullPath, folderName)
Sub FTPUpload(fullPath, folderName)
Const copyType = 16
waitTime = 80000
FTPUser = "Username"
FTPPass = "Password"
FTPHost = "HostName"
FTPDir = "/1/"
strFTP = "ftp://" & FTPUser & ":" & FTPPass & "@" & FTPHost & FTPDir
Set objFTP = oShell.NameSpace(strFTP)
'Upload all files in folder
If objFSO.FolderExists(fullPath) Then
Set objFolder = oShell.NameSpace(fullPath)
Wscript.Echo "Uploading folder " & fullPath & " 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
Function sprintf(sFmt, aData)
objSB.AppendFormat_4 sFmt, (aData)
sprintf = objSB.ToString()
objSB.Length = 0
End Function
该脚本将指定目录中的所有文件(fullPath变量)复制到目标目录(FTPDir变量)。但我想在FTP服务器中创建一个名称存储在folderName变量中的新文件夹,并将文件复制到新创建的文件夹中。我是vbscript的新手并且可以接受任何建议。
提前致谢,
答案 0 :(得分:1)
将行Set objFolder = oShell.NameSpace(fullPath)
替换为
Set objFolder = oShell.NameSpace(objFso.GetParentFolderName(fullPath))
和objFTP.CopyHere objFolder.Items, copyType
与
objFTP.CopyHere objFolder.ParseName(objFso.GetFileName(fullPath)), copyType
然后它应该工作。
这样,您的本地命名空间将是fullPath
的父文件夹,folderName
将是要复制到远程目录的项目。