我正在使用fluentftp库。
我分别有 2 台服务器,FTPserver 和 WebServer。所以我的方案是从 ftp 服务器下载大文件并通过 http ajax 响应将其发送到我的客户端。我创建了一个 webservice .asmx 文件和一个 web 方法来创建下载数据。
这是我发送数据块的代码,但浏览器中没有发生任何事情。
[WebMethod(enableSession: true)]
public void GetDownload(string brandName, string modelName, string osName, string file)
{
if (!FtpConnect())
throw new Exception("Error ftp connection.");
byte[] buffer = new byte[1024];
string path = "disk1/Drivers/" + GetFtpBrands(brandName) + "/" + modelName + "/" + osName + "/" +file;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.BufferOutput = true;
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + file);
FtpDataStream inputStream = (FtpDataStream) ftp.OpenRead(path,FtpDataType.Binary);
int read = 0;
while ((read = inputStream.Read(buffer, 0, buffer.Length)) > 0)
{
HttpContext.Current.Response.OutputStream.Write(buffer, 0, read);
HttpContext.Current.Response.Flush(); // Sends all currently buffered output to the client.
}
inputStream.Close();
HttpContext.Current.Response.OutputStream.Close();
}