本文介绍了VBscript,在FTP中创建目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在FTP中创建一个目录,目录的名称必须是我的电脑名称,



这里是我的代码,

  Dim FoldertoCreate,filesys,newfolder,Ob 
Set Ob = Wscript.CreateObject(Wscript.Network)
FoldertoCreate = ftp:// User:password @ ftpserver / url-path /& ob.ComputerName
设置filesys = CreateObject(Scripting.FileSystemObject)
如果不是filesys.FolderExists(FoldertoCreate)然后
设置newfolder = filesys.CreateFolder(FoldertoCreate)
End If

当我替换与任何本地目录,如D:/,它的工作原理:S



如何使其对我的ftp起作用

解决方案

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

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

Const ForWriting = 2

设置objFso = CreateObject(Scripting.FileSystemObject)
设置objFile = objFso.OpenTextFile( session.txt,ForWriting,vbTrue)

带有objFile
.WriteLineOPEN& strHost
.WriteLineUSER& strUser
.WriteLine strPass
.WriteLinemkdir sometestdirectory
.Close
结束

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

objFso.DeleteFilesession.txt,vbTrue


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

解决方案

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

这篇关于VBscript,在FTP中创建目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 10:56