MVC4 应用程序在 HomeController 的操作中从 FTP 服务器下载文件。使用 Visual Studio 2010 网络服务器和本地网络服务器 IIS Express 8 它可以工作。但是当我使用带有 ApplicationPoolIdenty 的本地网络服务器 IIS 7.5 时,下载不起作用:我没有收到命令“response = reqFTP.GetResponse()”的响应,并且出现以下异常:“操作有时间到”)。
当我关闭 Windows 防火墙时,它可以工作。我需要做什么?
Function FtpStart() As ActionResult
Dim downloadFiles As String()
Dim result As New StringBuilder()
Dim response As WebResponse = Nothing
Dim reader As StreamReader = Nothing
Try
Dim reqFTP As FtpWebRequest
reqFTP = DirectCast(FtpWebRequest.Create(New Uri("ftp://adress")),FtpWebRequest)
reqFTP.UseBinary = True
reqFTP.Credentials = New NetworkCredential("user", "pw")
reqFTP.EnableSsl = False
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory
reqFTP.Proxy = Nothing
reqFTP.KeepAlive = False
reqFTP.UsePassive = False
Debug.WriteLine("Get Response: ")
response = reqFTP.GetResponse()
Debug.WriteLine("Response received")
reader = New StreamReader(response.GetResponseStream())
Dim line As String = reader.ReadLine()
While line IsNot Nothing
result.Append(line)
result.Append(vbLf)
line = reader.ReadLine()
Debug.WriteLine("File: " & line)
End While
result.Remove(result.ToString().LastIndexOf(ControlChars.Lf), 1)
Return RedirectToAction("Index")
Catch ex As Exception
Debug.WriteLine(ex.ToString())
Return RedirectToAction("Index")
End Try
End Function