Vbscript 每10秒在web服务器中上载文件时出错
下面的代码是我用来上传没有循环的代码的,当我使用无循环功能时,代码可以正常工作。Vbscript 每10秒在web服务器中上载文件时出错,vbscript,Vbscript,下面的代码是我用来上传没有循环的代码的,当我使用无循环功能时,代码可以正常工作。 dim strURL Dim password Dim username Set wshShell = CreateObject("WScript.Shell") UploadDest= wshShell.ExpandEnvironmentStrings("https://webdav.pcloud.com/Public%20Folder/") UploadFile = wshShell.ExpandEnviro
dim strURL
Dim password
Dim username
Set wshShell = CreateObject("WScript.Shell")
UploadDest= wshShell.ExpandEnvironmentStrings("https://webdav.pcloud.com/Public%20Folder/")
UploadFile = wshShell.ExpandEnvironmentStrings("%username%.txt")
username = "abc@gmail.com"
password = "abc"
sData = getFileBytes(UploadFile, UploadType)
Set HttpReq =createobject("Microsoft.XMLHTTP")
strURL = UploadDest & "/" & UploadFile
HttpReq.Open "PUT",strURL,False,username,password
HttpReq.send sData
function getFileBytes(flnm,sType)
Dim objStream
Set objStream = CreateObject("ADODB.Stream")
if sType="binary" then
objStream.Type = 1 ' adTypeBinary
else
objStream.Type = 2 ' adTypeText
objStream.Charset ="ascii"
end if
objStream.Open
objStream.LoadFromFile flnm
if sType="binary" then
getFileBytes=objStream.Read 'read binary'
else
getFileBytes= objStream.ReadText 'read ascii'
end if
objStream.Close
Set objStream = Nothing
end function
set i = 0
Do While i = 0
dim strURL
Dim password
Dim username
Set wshShell = CreateObject("WScript.Shell")
UploadDest= wshShell.ExpandEnvironmentStrings("https://webdav.pcloud.com/Public%20Folder/")
UploadFile = wshShell.ExpandEnvironmentStrings("%username%.txt")
username = "abc@gmail.com"
password = "abc"
sData = getFileBytes(UploadFile, UploadType)
Set HttpReq =createobject("Microsoft.XMLHTTP")
strURL = UploadDest & "/" & UploadFile
HttpReq.Open "PUT",strURL,False,username,password
HttpReq.send sData
function getFileBytes(flnm,sType)
Dim objStream
Set objStream = CreateObject("ADODB.Stream")
if sType="binary" then
objStream.Type = 1 ' adTypeBinary
else
objStream.Type = 2 ' adTypeText
objStream.Charset ="ascii"
end if
objStream.Open
objStream.LoadFromFile flnm
if sType="binary" then
getFileBytes=objStream.Read 'read binary'
else
getFileBytes= objStream.ReadText 'read ascii'
end if
objStream.Close
Set objStream = Nothing
end function
WScript.Sleep(10000)
loop
但当我在循环中使用上述代码时,第12行出现语法错误
function getFileBytes(flnm,sType)
我使用以下代码每10秒上传一次循环中的文件。
dim strURL
Dim password
Dim username
Set wshShell = CreateObject("WScript.Shell")
UploadDest= wshShell.ExpandEnvironmentStrings("https://webdav.pcloud.com/Public%20Folder/")
UploadFile = wshShell.ExpandEnvironmentStrings("%username%.txt")
username = "abc@gmail.com"
password = "abc"
sData = getFileBytes(UploadFile, UploadType)
Set HttpReq =createobject("Microsoft.XMLHTTP")
strURL = UploadDest & "/" & UploadFile
HttpReq.Open "PUT",strURL,False,username,password
HttpReq.send sData
function getFileBytes(flnm,sType)
Dim objStream
Set objStream = CreateObject("ADODB.Stream")
if sType="binary" then
objStream.Type = 1 ' adTypeBinary
else
objStream.Type = 2 ' adTypeText
objStream.Charset ="ascii"
end if
objStream.Open
objStream.LoadFromFile flnm
if sType="binary" then
getFileBytes=objStream.Read 'read binary'
else
getFileBytes= objStream.ReadText 'read ascii'
end if
objStream.Close
Set objStream = Nothing
end function
set i = 0
Do While i = 0
dim strURL
Dim password
Dim username
Set wshShell = CreateObject("WScript.Shell")
UploadDest= wshShell.ExpandEnvironmentStrings("https://webdav.pcloud.com/Public%20Folder/")
UploadFile = wshShell.ExpandEnvironmentStrings("%username%.txt")
username = "abc@gmail.com"
password = "abc"
sData = getFileBytes(UploadFile, UploadType)
Set HttpReq =createobject("Microsoft.XMLHTTP")
strURL = UploadDest & "/" & UploadFile
HttpReq.Open "PUT",strURL,False,username,password
HttpReq.send sData
function getFileBytes(flnm,sType)
Dim objStream
Set objStream = CreateObject("ADODB.Stream")
if sType="binary" then
objStream.Type = 1 ' adTypeBinary
else
objStream.Type = 2 ' adTypeText
objStream.Charset ="ascii"
end if
objStream.Open
objStream.LoadFromFile flnm
if sType="binary" then
getFileBytes=objStream.Read 'read binary'
else
getFileBytes= objStream.ReadText 'read ascii'
end if
objStream.Close
Set objStream = Nothing
end function
WScript.Sleep(10000)
loop
不能在
循环中定义函数
如下重写以定义循环外的函数:
Dim i
Do While i = 0
dim strURL
Dim password
Dim username
Set wshShell = CreateObject("WScript.Shell")
UploadDest= wshShell.ExpandEnvironmentStrings("https://webdav.pcloud.com/Public%20Folder/")
UploadFile = wshShell.ExpandEnvironmentStrings("%username%.txt")
username = "abc@gmail.com"
password = "abc"
sData = getFileBytes(UploadFile, UploadType)
Set HttpReq =createobject("Microsoft.XMLHTTP")
strURL = UploadDest & "/" & UploadFile
HttpReq.Open "PUT",strURL,False,username,password
HttpReq.send sData
WScript.Sleep(10000)
loop
function getFileBytes(flnm,sType)
Dim objStream
Set objStream = CreateObject("ADODB.Stream")
if sType="binary" then
objStream.Type = 1 ' adTypeBinary
else
objStream.Type = 2 ' adTypeText
objStream.Charset ="ascii"
end if
objStream.Open
objStream.LoadFromFile flnm
if sType="binary" then
getFileBytes=objStream.Read 'read binary'
else
getFileBytes= objStream.ReadText 'read ascii'
end if
objStream.Close
Set objStream = Nothing
end function
这不是JavaScript。看起来像是某种类型的BASIC。错误:需要对象:“[number:0]”。请更正,先生。如果您想让我为您修改代码,我可以给您发一个报价。@Geert Bellekens我是一名学生。:)那么,我怎样才能给你一个报价呢?那么我想你必须自己调试和修复你的代码。@Geert Bellekens true先生&我一直在尝试。