MVC4应用程序通过来自HomeController的操作从FTP服务器下载文件。在visual Studio2010 the服务器和本地the服务器IIS Express 8上,它可以正常工作。但是当我使用带有ApplicationPoolIdenty的本地when服务器IIS7.5时,下载无法工作:我没有收到命令"response = reqFTP.GetResponse()“的响应,并且出现以下异常:”操作已超时“)。
当我关闭Windows-Firewall时,它工作了。我需要做什么?
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发布于 2014-12-16 09:10:49
今天早些时候我在我的web服务器上遇到了这个问题。您必须在防火墙上为端口20和21的TCP入站规则设置一个规则。应显示Local port = all ports,remote ports = 20-21。还要确保在advanced选项卡上,选中了domain、private和public的所有三个复选标记。我的防火墙已经为端口21设置了FTP防火墙规则,但没有为20设置规则,一旦我为端口20设置了规则,它就起作用了。
希望这能有所帮助
https://stackoverflow.com/questions/13821832
复制相似问题