ASP访问FTP图片并下载保存
时间: 2023-12-19 21:07:09 浏览: 33
你可以使用 ASP 的 File System Object(FSO)来访问 FTP 服务器上的图片并进行下载保存。以下是一个示例代码:
```asp
<%
Dim objFSO, objFTP, objFile
Dim strFTPUrl, strLocalPath
' FTP 服务器信息
strFTPUrl = "ftp://ftp.example.com/path/to/image.jpg"
strLocalPath = "C:\path\to\save\image.jpg"
' 创建 File System Object
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
' 创建 FTP 对象
Set objFTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
objFTP.Open "GET", strFTPUrl, False
objFTP.Send
' 检查 FTP 请求是否成功
If objFTP.Status = 200 Then
' 创建本地文件
Set objFile = objFSO.CreateTextFile(strLocalPath, True)
' 写入文件内容
objFile.Write objFTP.ResponseBody
' 关闭文件
objFile.Close
Response.Write "文件下载成功!"
Else
Response.Write "文件下载失败!"
End If
' 清理对象
Set objFile = Nothing
Set objFTP = Nothing
Set objFSO = Nothing
%>
```
请确保将 `strFTPUrl` 替换为实际的 FTP 图片 URL,将 `strLocalPath` 替换为要保存到的本地路径。此代码使用了 ASP 的 `MSXML2.ServerXMLHTTP` 对象来发送 FTP 请求,并使用 File System Object 来创建本地文件并写入内容。最后,根据 FTP 请求的状态码判断文件是否成功下载。
注意:为了使此代码正常工作,你的服务器