首页 > 解决方案 > 通过 OpenFileDialog 浏览设备并通过 FTP 下载

问题描述

我正在尝试通过 FTP 从设备下载一些文件。但现在我有一个问题OpenFileDialog。当我选择一个文件时,它首先开始缓存,这需要很长时间。我只想知道我在对话框中选择了哪个文件,没有别的。然后,通过WebClient.

这是一个代码片段:

OpenFileDialog dialog = new OpenFileDialog();
dialog.InitialDirectory = ftpAddress;

DialogResult result = dialog.ShowDialog(this);

if(result != DialogResult.OK)
{
    return false;
}

string selectedLogFile = dialog.FileName;

WebClient webclient = new WebClient();
webclient.Credentials = new NetworkCredential(login, password);

webclient.DownloadFile(ftpAddress+ selectedLogFile, exportTo + selectedLogFile);

标签: c#.netwinformsftpopenfiledialog

解决方案


如果您在 中选择 FTP 服务器上的文件OpenFileDialog,它实际上会将文件下载到本地临时文件夹并返回该临时文件的路径。以同样的方式,就像您将文件的 HTTP URL 粘贴到对话框中一样。

没有办法让它与 FTP 路径一起工作。为此,您必须实现自己的自定义对话框。

实际上,在 Windows 10 中甚至连浏览 FTP 服务器也被弃用了。


推荐阅读