File upload 使用经典ASP上载实用程序将文件从一台服务器上载到另一台服务器
我有一个目前部署在服务器a上的经典ASP应用程序。我有“上载附件”功能,通过该功能,我试图使用下面的经典ASP代码将文件上载到服务器a(我的ASP应用程序部署在IIS中)。当我尝试在服务器A上上载文件时,我的文件被成功且快速地上载。但是,当我试图将文件上载到另一台服务器B时,我无法使用相同的实用程序ASP代码上载文件。我的问题是我的应用程序部署在服务器A上,我需要通过应用程序将文件上载到服务器B。是否可能?请帮忙 我的当前上载文件实用程序代码:File upload 使用经典ASP上载实用程序将文件从一台服务器上载到另一台服务器,file-upload,asp-classic,File Upload,Asp Classic,我有一个目前部署在服务器a上的经典ASP应用程序。我有“上载附件”功能,通过该功能,我试图使用下面的经典ASP代码将文件上载到服务器a(我的ASP应用程序部署在IIS中)。当我尝试在服务器A上上载文件时,我的文件被成功且快速地上载。但是,当我试图将文件上载到另一台服务器B时,我无法使用相同的实用程序ASP代码上载文件。我的问题是我的应用程序部署在服务器A上,我需要通过应用程序将文件上载到服务器B。是否可能?请帮忙 我的当前上载文件实用程序代码: <% Class Loader Pr
<% Class Loader
Private dict
Private Sub Class_Initialize
Set dict = Server.CreateObject("Scripting.Dictionary")
End Sub
Private Sub Class_Terminate
If IsObject(intDict) Then
intDict.RemoveAll
Set intDict = Nothing
End If
If IsObject(dict) Then
dict.RemoveAll
Set dict = Nothing
End If
End Sub
Public Property Get Count
Count = dict.Count
End Property
Public Sub Initialize
If Request.TotalBytes > 0 Then
response.write(Request.TotalBytes)
Dim binData
binData = Request.BinaryRead(Request.TotalBytes)
getData binData
End If
End Sub
Public Function getFileData(name)
If dict.Exists(name) Then
getFileData = dict(name).Item("Value")
Else
getFileData = ""
End If
End Function
Public Function getValue(name)
Dim gv
If dict.Exists(name) Then
gv = CStr(dict(name).Item("Value"))
gv = Left(gv,Len(gv)-2)
getValue = gv
Else
getValue = ""
End If
End Function
Public Function saveToFile(name, path)
If dict.Exists(name) Then
Dim temp
temp = dict(name).Item("Value")
Dim fso
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Dim file
'File write Exception handling - David
On Error Resume Next
Set file = fso.CreateTextFile(path)
For tPoint = 1 to LenB(temp)
file.Write Chr(AscB(MidB(temp,tPoint,1)))
Next
file.Close
If Err.Number<>0 then
saveToFile = False
else
saveToFile = True
End if
On Error Goto 0
Else
saveToFile = False
End If
End Function
Public Function getFileName(name)
If dict.Exists(name) Then
Dim temp, tempPos
temp = dict(name).Item("FileName")
tempPos = 1 + InStrRev(temp, "\")
getFileName = Mid(temp, tempPos)
Else
getFileName = ""
End If
End Function
Public Function getFilePath(name)
If dict.Exists(name) Then
Dim temp, tempPos
temp = dict(name).Item("FileName")
tempPos = InStrRev(temp, "\")
getFilePath = Mid(temp, 1, tempPos)
Else
getFilePath = ""
End If
End Function
Public Function getFilePathComplete(name)
If dict.Exists(name) Then
getFilePathComplete = dict(name).Item("FileName")
Else
getFilePathComplete = ""
End If
End Function
Public Function getFileSize(name)
If dict.Exists(name) Then
getFileSize = LenB(dict(name).Item("Value"))
Else
getFileSize = 0
End If
End Function
Public Function getFileSizeTranslated(name)
If dict.Exists(name) Then
temp = LenB(dict(name).Item("Value"))
If temp <= 1024 Then
getFileSizeTranslated = temp & " bytes"
Else
temp = FormatNumber((temp / 1024), 2)
getFileSizeTranslated = temp & " kilobytes"
End If
Else
getFileSizeTranslated = ""
End If
End Function
Public Function getContentType(name)
If dict.Exists(name) Then
getContentType = dict(name).Item("ContentType")
Else
getContentType = ""
End If
End Function
Private Sub getData(rawData)
Dim separator
separator = MidB(rawData, 1, InstrB(1, rawData, ChrB(13)) - 1)
Dim lenSeparator
lenSeparator = LenB(separator)
Dim currentPos
currentPos = 1
Dim inStrByte
inStrByte = 1
Dim value, mValue
Dim tempValue
tempValue = ""
While inStrByte > 0
inStrByte = InStrB(currentPos, rawData, separator)
mValue = inStrByte - currentPos
If mValue > 1 Then
value = MidB(rawData, currentPos, mValue)
Dim begPos, endPos, midValue, nValue
Dim intDict
Set intDict = Server.CreateObject("Scripting.Dictionary")
begPos = 1 + InStrB(1, value, ChrB(34))
endPos = InStrB(begPos + 1, value, ChrB(34))
nValue = endPos
Dim nameN
nameN = MidB(value, begPos, endPos - begPos)
Dim nameValue, isValid
isValid = True
If InStrB(1, value, stringToByte("Content-Type")) > 1 Then
begPos = 1 + InStrB(endPos + 1, value, ChrB(34))
endPos = InStrB(begPos + 1, value, ChrB(34))
If endPos = 0 Then
endPos = begPos + 1
isValid = False
End If
midValue = MidB(value, begPos, endPos - begPos)
intDict.Add "FileName", trim(byteToString(midValue))
begPos = 14 + InStrB(endPos + 1, value, stringToByte("Content-Type:"))
endPos = InStrB(begPos, value, ChrB(13))
midValue = MidB(value, begPos, endPos - begPos)
intDict.Add "ContentType", trim(byteToString(midValue))
begPos = endPos + 4
endPos = LenB(value)
nameValue = MidB(value, begPos, ((endPos - begPos) - 1))
Else
nameValue = trim(byteToString(MidB(value, nValue + 5)))
End If
If isValid = True Then
intDict.Add "Value", nameValue
intDict.Add "Name", nameN
dict.Add byteToString(nameN), intDict
End If
End If
currentPos = lenSeparator + inStrByte
Wend
End Sub
End Class
Private Function stringToByte(toConv)
Dim tempChar
For i = 1 to Len(toConv)
tempChar = Mid(toConv, i, 1)
stringToByte = stringToByte & chrB(AscB(tempChar))
Next
End Function
Private Function byteToString(toConv)
For i = 1 to LenB(toConv)
byteToString = byteToString & Chr(AscB(MidB(toConv,i,1)))
Next
End Function
%>
0那么
response.write(Request.TotalBytes)
Dim binData
binData=Request.BinaryRead(Request.TotalBytes)
获取数据绑定数据
如果结束
端接头
公共函数getFileData(名称)
如果dict.存在(名称),则
getFileData=dict(名称)。项(“值”)
其他的
getFileData=“”
如果结束
端函数
公共函数getValue(名称)
暗gv
如果dict.存在(名称),则
gv=CStr(目录(名称).项目(“值”))
gv=左(gv,透镜(gv)-2)
getValue=gv
其他的
getValue=“”
如果结束
端函数
公共函数saveToFile(名称、路径)
如果dict.存在(名称),则
暗温
temp=dict(名称)。项目(“值”)
模糊fso
设置fso=Server.CreateObject(“Scripting.FileSystemObject”)
暗文件
'文件写入异常处理-David
出错时继续下一步
Set file=fso.CreateTextFile(路径)
对于t点=1至透镜B(温度)
写入Chr(AscB(MidB(temp,tPoint,1)))
下一个
文件,关闭
如果错误号为0,则
saveToFile=False
其他的
saveToFile=True
如果结束
错误转到0
其他的
saveToFile=False
如果结束
端函数
公共函数getFileName(名称)
如果dict.存在(名称),则
暗温
temp=dict(name).Item(“文件名”)
tempPos=1+InStrRev(温度,“\”)
getFileName=Mid(临时、临时位置)
其他的
getFileName=“”
如果结束
端函数
公共函数getFilePath(名称)
如果dict.存在(名称),则
暗温
temp=dict(name).Item(“文件名”)
tempPos=InStrRev(温度,“\”)
getFilePath=Mid(临时、1、临时位置)
其他的
getFilePath=“”
如果结束
端函数
公共函数getFilePathComplete(名称)
如果dict.存在(名称),则
getFilePathComplete=dict(name).Item(“文件名”)
其他的
getFilePathComplete=“”
如果结束
端函数
公共函数getFileSize(名称)
如果dict.存在(名称),则
getFileSize=LenB(dict(name).Item(“Value”))
其他的
getFileSize=0
如果结束
端函数
公共函数getFileSizeTranslated(名称)
如果dict.存在(名称),则
temp=LenB(dict(名称).项目(“值”))
如果温度为0
inStrByte=InStrB(当前位置、原始数据、分隔符)
M值=仪表字节-当前位置
如果mValue>1,则
值=MidB(原始数据、当前位置、MVValue)
Dim begPos、endPos、中值、nValue
模糊积分
设置intDict=Server.CreateObject(“Scripting.Dictionary”)
begPos=1+InStrB(1,值,ChrB(34))
endPos=InStrB(begPos+1,值,ChrB(34))
nValue=endPos
暗名
nameN=MidB(值,begPos,endPos-begPos)
Dim名称值,无效
isValid=True
如果InStrB(1,value,stringToByte(“内容类型”))>1,则
begPos=1+InStrB(endPos+1,值,ChrB(34))
endPos=InStrB(begPos+1,值,ChrB(34))
如果endPos=0,则
endPos=begPos+1
isValid=False
如果结束
midValue=MidB(值,begPos,endPos-begPos)
intDict.Add“FileName”,trim(byteToString(中值))
begPos=14+InStrB(endPos+1,值,stringToByte(“内容类型:”))
endPos=InStrB(begPos,value,ChrB(13))
midValue=MidB(值,begPos,endPos-begPos)
intDict.添加“ContentType”,修剪(byteToString(中值))
begPos=endPos+4
endPos=LenB(值)
nameValue=MidB(值,begPos,((endPos-begPos)-1))
其他的
nameValue=trim(byteToString(MidB(value,nValue+5)))
如果结束
如果isValid=True,则
输入。添加“值”,名称值
输入。添加“名称”,名称
按名称添加命令,intDict
如果结束
如果结束
currentPos=lenSeparator+inStrByte
温德
端接头
末级
私有函数stringToByte(toConv)
暗tempChar
对于i=1至Len(toConv)
tempChar=Mid(toConv,i,1)
stringToByte=stringToByte和chrB(AscB(tempChar))
下一个
端函数
通过tetostring(toConv)实现的私有函数
对于i=1至LenB(toConv)
byteToString=byteToString&Chr(AscB(MidB(toConv,i,1)))
下一个
端函数
%>
可能是IIS中windows的默认上载大小:196Kb 我的猜测是,您对试图上载文件的目录没有写入权限,但我需要更多信息。您收到了什么错误消息?谢谢您的回复。但是,我确实对目录有写权限。上载大小超过5 MB左右的文件时,我遇到超时错误。但如果文件大小约为1KB,则会成功上载。