i wrote asp.net Webservice to generate ftp download link and send it to client browser, so client can download it.
(我编写了asp.net Web服务以生成ftp下载链接并将其发送到客户端浏览器,以便客户端可以下载它。)
the link is like this: (链接是这样的:)
<a href='ftp://test:test@10:10:10:10:21/test.txt'>download</a>
i send that link trough Ajax response call.
(我通过Ajax响应链接发送了该链接。)
so how can i prevent users to view my ftp user and password?
(所以如何防止用户查看我的ftp用户名和密码?)
or how to encrypt link? (或如何加密链接?)
approach #2:
(方法2:)
to avoid above link i wrote code to send chunk of data but nothing is happening in browser.
(为了避免上述链接,我编写了发送数据块的代码,但是浏览器中没有任何反应。)
(I am using fluentftp library . ) ((我正在使用fluentftp库。))
[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();
}
and jquery :
(和jquery:)
function GetDlLink(brandName, model, os, file) {
$.ajax({
type: 'POST',
url: 'WS/Drivers.asmx/GetDownload',
data: JSON.stringify(
{
brandName: brandName,
modelName: model,
osName: os,
file: file
}),
cache: false,
contentType: 'application/json; charset=utf-8',
processData: false,
responseType: 'blob',
// ******* this is important for getting binary response types *******************
xhrFields: {
responseType: 'blob'
},
//==================================================================
// function for openning browser download dialog
success: function(data) {
var blob = new Blob([data]);
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = file;
link.click();
},
error: function(xhr, ajaxOptions, thrownError) {
alert("error");
}
});
}
but nothing is happening in browser!!!
(但是在浏览器中什么也没发生!!!)
ask by Dr developer translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…