在我的应用程序中,我要求客户端/用户需要将视频文件从ftp服务器下载到本地计算机。
通过使用下面的代码,我可以从ftp下载文件,但它只保存在我的应用程序服务器而不是本地客户端pc中。 我想将文件下载到客户端电脑,下载前应该询问对话框。
我的代码正在关注,
string ResponseDescription = "";
string PureFileName = new FileInfo(filename).Name;
string DownloadedFilePath = @"E:\\aa\\" + PureFileName;
String downloadUrl = String.Format("{0}/{1}", "ftp://abcd.int/", filename);
FtpWebRequest req = (FtpWebRequest)FtpWebRequest.Create(downloadUrl);
req.Method = WebRequestMethods.Ftp.DownloadFile;
req.Credentials = new NetworkCredential("username", "password");
req.UseBinary = true;
req.Proxy = null;
FtpWebResponse response = (FtpWebResponse)req.GetResponse();
Stream stream = response.GetResponseStream();
byte[] buffer = new byte[2048];
FileStream fs = new FileStream(DownloadedFilePath, FileMode.Create);
int ReadCount = stream.Read(buffer, 0, buffer.Length);
while (ReadCount > 0)
{
fs.Write(buffer, 0, ReadCount);
ReadCount = stream.Read(buffer, 0, buffer.Length);
}
ResponseDescription = response.StatusDescription;
fs.Close();
stream.Close();