VBscript,在FTP中创建目录

VBscript,在FTP中创建目录,vbscript,upload,ftp,directory,Vbscript,Upload,Ftp,Directory,我想在FTP中创建一个目录,该目录的名称必须与我的计算机名相同 这是我的密码 Dim FoldertoCreate, filesys, newfolder, Ob Set Ob = Wscript.CreateObject("Wscript.Network" ) FoldertoCreate = "ftp://user:password@ftpserver/url-path/" & ob.ComputerName Set filesys = CreateObject("Scripting

我想在FTP中创建一个目录,该目录的名称必须与我的计算机名相同

这是我的密码

Dim FoldertoCreate, filesys, newfolder, Ob
Set Ob = Wscript.CreateObject("Wscript.Network" )
FoldertoCreate = "ftp://user:password@ftpserver/url-path/" & ob.ComputerName
Set filesys = CreateObject("Scripting.FileSystemObject")
If Not filesys.FolderExists(FoldertoCreate) Then
   Set newfolder = filesys.CreateFolder(FoldertoCreate)
End If
但是,当我替换为任何本地目录(如D:/)时,此代码不起作用,它可以工作:S


如何使其也适用于我的ftp

FileSystemObject不支持ftp。Shell自动化对象确实如此,但它似乎不喜欢NewFolder方法。这使我们可以使用无人参与的FTP会话自动执行FTP.exe命令。它可能看起来像这样

strUser = "myusername"
strPass = "mypassword"
strHost = "ftp.myhost.com"

Const ForWriting = 2

Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFile = objFso.OpenTextFile("session.txt", ForWriting, vbTrue)

With objFile
    .WriteLine "OPEN " & strHost
    .WriteLine "USER " & strUser
    .WriteLine strPass
    .WriteLine "mkdir sometestdirectory"
    .Close
End With

strFTP = "%systemroot%\System32\ftp.exe -s:session.txt"
Set WshShell = CreateObject("WScript.Shell")
strFTP = WshShell.ExpandEnvironmentStrings(strFTP)
WshShell.Run strFTP,, vbTrue

objFso.DeleteFile "session.txt", vbTrue

Scripting.FileSystemObject用于文件系统,它不支持FTP。那么我使用什么?你能告诉我吗?这不是我的iPhone的wokrng你是否确保strUser、strPass和strHost包含正确的凭据?您是否得到任何错误?在哪里使用strHost变量?它已定义,但未在其他任何地方使用。@anilca对此深表歉意。我更正了代码示例。注意“开放”行。谢谢@Nilpo。我认为,WriteLine strPassword行必须是WriteLine strPass