通过 OpenFileDialog 浏览设备并通过 FTP 下载
Browse device via OpenFileDialog and download via 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);
如果您 select 在 OpenFileDialog
服务器上的 FTP 文件,它实际上会将文件下载到本地临时文件夹,并 return 您提供该文件的路径临时文件。以同样的方式,就像您将 HTTP URL 粘贴到对话框中的文件一样。
无法使用 FTP 路径。为此,您必须实现自己的自定义对话框。
事实上,甚至浏览 FTP 服务器在 Windows 10 中也被弃用了。
我正在尝试通过 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);
如果您 select 在 OpenFileDialog
服务器上的 FTP 文件,它实际上会将文件下载到本地临时文件夹,并 return 您提供该文件的路径临时文件。以同样的方式,就像您将 HTTP URL 粘贴到对话框中的文件一样。
无法使用 FTP 路径。为此,您必须实现自己的自定义对话框。
事实上,甚至浏览 FTP 服务器在 Windows 10 中也被弃用了。