-1

我在 pcloud 服务器上有一个文件 admin.txt,我的电脑用户名是 admin.所以我尝试使用以下 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 行
char 1
错误:参数不正确。
代码:80070057
来源:msxml3.dll

注意: 在线

WScript.Echo "user name: " & strUserName

它显示了我的 admin.txt 名称。但是上线

myURL = "https://webdav.pcloud.com/public%20folder/%username%.txt"

它开始搜索%username%.txt下载而不是admin.txt我要下载的。

4

1 回答 1

-1

问题已解决,代码按预期工作。

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
于 2018-10-24T12:48:55.980 回答