我在pcloud服务器上有一个文件admin.txt,我的PC用户名是admin.so,所以我尝试使用以下vscript获取文件admin.txt。
Dim myURL
Dim password
Dim username
Dim strUserName
Set objShell = CreateObject("WScript.Shell")
Set wshShell = CreateObject("WScript.Shell")
strUserName = wshShell.ExpandEnvironmentStrings("%USERNAME%.txt")
WScript.Echo "User Name: " & strUserName
myURL = "https://webdav.pcloud.com/Public%20Folder/%USERNAME%.txt"
username = "xyz@gmail.com"
password = "xyz"
Dim HttpReq
Set HttpReq = CreateObject("MSXML2.XMLHTTP.3.0")
HttpReq.Open "GET", myURL, False, username, password
HttpReq.Send
myURL = HttpReq.ResponseBody
If HttpReq.Status = 200 Then
Set oStrm = CreateObject("ADODB.Stream")
oStrm.Open
oStrm.Type = 1
oStrm.Write HttpReq.ResponseBody
oStrm.SaveToFile "D:/%USERNAME%.txt", 2 ' change your path here...
oStrm.Close
End If
错误消息:
第16行
字符1
错误:参数不正确。
代码:80070057
来源:msxml3.dll
注意: 在线
WScript.Echo "user name: " & strUserName
它显示了我的admin.txt名称。但是在线
myURL = "https://webdav.pcloud.com/public%20folder/%username%.txt"
它开始搜索%username%.txt
而不是我要下载的admin.txt
。
答案 0 :(得分:0)
问题已解决,代码按预期工作。
Dim myURL
Dim password
Dim username
Set wshShell = CreateObject("WScript.Shell")
strUserName = wshShell.ExpandEnvironmentStrings("%USERNAME%.txt")
myURL = wshShell.ExpandEnvironmentStrings("https://webdav.pcloud.com/Public%20Folder/%USERNAME%.txt")
username = "xyz@gmail.com"
password = "xyz"
Dim HttpReq
Set HttpReq = CreateObject("MSXML2.XMLHTTP.3.0")
HttpReq.Open "GET", myURL, False, username, password
HttpReq.Send
myURL = HttpReq.ResponseBody
If HttpReq.Status = 200 Then
Set oStrm = CreateObject("ADODB.Stream")
oStrm.Open
oStrm.Type = 1
oStrm.Write HttpReq.ResponseBody
oStrm.SaveToFile wshShell.ExpandEnvironmentStrings("D:/%USERNAME%.txt"), 2
oStrm.Close
End If