在 ftp 服务器中创建文件夹
Creating folder in ftp server
我有一个 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 的新手,愿意接受任何建议。
提前致谢,
将行 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
将成为要复制到远程目录的项目。
我有一个 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 的新手,愿意接受任何建议。
提前致谢,
将行 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
将成为要复制到远程目录的项目。