VBscript,在FTP中创建目录

发布于 2025-01-07 09:39:09 字数 604 浏览 1 评论 0原文

我想在 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

但是当我替换 ftp://user:password@ftpserver/url-path 与任何本地目录(如 D:/ ),它的工作原理:S

如何使其适用于我的 ftp也

I would like to create a directory in FTP, the name of the directory must be as my computer name,

here is my code,

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

This code doesn't work however when i replace ftp://user:password@ftpserver/url-path with any local directory like D:/ , it works :S

how to make it work for my ftp too

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘羡 2025-01-14 09:39:09

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

The FileSystemObject does not support FTP. The Shell Automation Object does, but it doesn't seem to like the NewFolder method. That leaves us with automating the FTP.exe command using an unattended FTP session. It might look something like this.

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文