Asp.net 是否可以使用脚本将文件从UNC源复制到webDav目标?

Asp.net 是否可以使用脚本将文件从UNC源复制到webDav目标?,asp.net,vbscript,asp-classic,webdav,Asp.net,Vbscript,Asp Classic,Webdav,我在一个非常大、复杂的内部网环境中工作。我遇到了一个我似乎无法解决的非常独特的问题 警告 我提到的技术非常过时,这是is必须保持的方式。我在一家非常大的企业工作,他们有大量的遗产。我通常是在现代方面工作,但这件事被放在了我的膝盖上 问题: Set oShell = CreateObject("WScript.Shell") strCommand = oShell.Run("Xcopy ""sourceLocation"" ""destination location"" /S /Y", 0,

我在一个非常大、复杂的内部网环境中工作。我遇到了一个我似乎无法解决的非常独特的问题

警告

我提到的技术非常过时,这是is必须保持的方式。我在一家非常大的企业工作,他们有大量的遗产。我通常是在现代方面工作,但这件事被放在了我的膝盖上

问题:

Set oShell = CreateObject("WScript.Shell") 
strCommand = oShell.Run("Xcopy ""sourceLocation"" ""destination location"" /S /Y", 0, True) 

If strCommand <> 0 Then 
MsgBox "File Copy Error: " & strCommand 
Else 
MsgBox "Done" 

End If
<%

dim objFSOpublish
set objFSOpublish = CreateObject("Scripting.FileSystemObject")
strCurrentUNCfull = "sourcePath"
mPublishPath = "destinationPath"

objFSOpublish.CopyFile strCurrentUNCfull, mPublishPath 


set objFSOpublish = nothing

%>
我们在IIS 7.x服务器上有一个路径为\serverName\shareName\wwwroot\myfile.jpg的文件。我需要使用ASP、vbscript或其他类似的web技术将此文件复制到其他web服务器的webDav位置。对于许多安全问题,我没有访问webDav UNC路径的权限,只有http:path。我可以使用windows资源管理器映射此驱动器并访问http:位置。我甚至可以手动复制、创建和删除文件。然而,当我尝试使用脚本时,我却无计可施

我对vbscript不是很在行,我的尝试太简单了:

尝试1:

Set oShell = CreateObject("WScript.Shell") 
strCommand = oShell.Run("Xcopy ""sourceLocation"" ""destination location"" /S /Y", 0, True) 

If strCommand <> 0 Then 
MsgBox "File Copy Error: " & strCommand 
Else 
MsgBox "Done" 

End If
<%

dim objFSOpublish
set objFSOpublish = CreateObject("Scripting.FileSystemObject")
strCurrentUNCfull = "sourcePath"
mPublishPath = "destinationPath"

objFSOpublish.CopyFile strCurrentUNCfull, mPublishPath 


set objFSOpublish = nothing

%>
Set oShell=CreateObject(“WScript.Shell”)
strCommand=oShell.Run(“Xcopy”“sourceLocation”“destination location”“/S/Y”,0,True)
如果strCommand为0,则
MsgBox“文件复制错误:”&strCommand
其他的
MsgBox“完成”
如果结束
尝试2:

Set oShell = CreateObject("WScript.Shell") 
strCommand = oShell.Run("Xcopy ""sourceLocation"" ""destination location"" /S /Y", 0, True) 

If strCommand <> 0 Then 
MsgBox "File Copy Error: " & strCommand 
Else 
MsgBox "Done" 

End If
<%

dim objFSOpublish
set objFSOpublish = CreateObject("Scripting.FileSystemObject")
strCurrentUNCfull = "sourcePath"
mPublishPath = "destinationPath"

objFSOpublish.CopyFile strCurrentUNCfull, mPublishPath 


set objFSOpublish = nothing

%>


我不知道如果没有webDav UNC路径,这是否可能实现,因为我对webDav没有太多经验。如果可能的话,我已经在这个领域耗尽了有限的知识,急需帮助。我不知疲倦地搜索谷歌,试图找到一个类似的问题,但毫无结果。我们将非常感谢您提供的任何帮助或指导。

您将需要这样做:

On Error Resume Next

sUrl = "YourURLHere"
sFile = "UNCPathToYourFile"

'Here we are just reading your file into an ODB
'stream so we can manipulate it
Set oStream = CreateObject("ADODB.Stream")
oStream.Mode = 3
oStream.Type = 1
oStream.Open
oStream.LoadFromFile(sFile)

'Here we are doing the upload of the oStream
'object we just created.
Set oHTTP = CreateObject("MSXML2.ServerXMLHTTP")
oHTTP.Open "POST", sUrl, False
oHTTP.SetRequestHeader "Content-Length", oStream.Size
oHTTP.Send oStream.Read(oStream.Size)

'Check for errors.
If Err = 0 Then
  Wscript.Echo oHTTP.responseText 
Else
  Wscript.Echo "Upload Error!" & vbCrLf & Err.Description
End If

'Optionally close out our objects
oStream.Close
Set oStream = Nothing
Set oHTTP = Nothing

下面是我目前正在使用的代码,用于实际文件路径的编辑。如果你看到任何不正确的地方,请告诉我

页面另存为.ASP。

<%
sUrl = "http://server.site.com:80/subDomain/wwwroot/"
sFile = "\\server\developmentShare\wwwroot\page.htm"

'Here we are just reading your file into an ODB
'stream so we can manipulate it
Set oStream = Server.CreateObject("ADODB.Stream")
oStream.Mode = 3
oStream.Type = 1
oStream.Open
oStream.LoadFromFile(sFile)


'Here we are doing the upload of the oStream
'object we just created.
Set oHTTP = CreateObject("MSXML2.ServerXMLHTTP")
oHTTP.Open "POST", sUrl, False
oHTTP.SetRequestHeader "Content-Length", oStream.Size
oHTTP.Send oStream.Read(oStream.Size)

'Check for errors.
If Err = 0 Then

Wscript.Echo oHTTP.responseText 
 Else
Wscript.Echo "Upload Error!" & vbCrLf & Err.Description
 End If

'Optionally close out our objects
oStream.Close
Set oStream = Nothing
Set oHTTP = Nothing

%>


+1我本来打算回答类似的问题,但使用“PUT”我试图实现这一点,但什么也没发生。我没有收到任何类型的错误,但文件也不在目标位置。为了确保清楚,我将webdav url放在了sURL位置,并将要复制的文件的UNC路径放在了sFile位置。对吗?请将“On Error Resume Next”注释掉,查看是否抛出错误。注释掉“On Error Resume Next”后,我收到以下错误:Microsoft VBScript运行时错误“800a01a8”必需对象:“”它引用的行包含Wscript.Echo oHTTP.responseText。但是,如果脚本有那么远,文件不应该在新位置吗?这很奇怪。您不应该获取所需的对象,因为oHTTP对象显然已成功创建。如果你使用上面的代码,我不明白为什么会发生这种情况。也许您可以粘贴您正在使用的实际代码和实际行号?