c# - 通过 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);
解决方案
如果您在 中选择 FTP 服务器上的文件OpenFileDialog
,它实际上会将文件下载到本地临时文件夹并返回该临时文件的路径。以同样的方式,就像您将文件的 HTTP URL 粘贴到对话框中一样。
没有办法让它与 FTP 路径一起工作。为此,您必须实现自己的自定义对话框。
实际上,在 Windows 10 中甚至连浏览 FTP 服务器也被弃用了。
推荐阅读
- python - 使用 pip 安装程序安装 web3 时出现问题(cytoolz 错误)
- powershell - 找不到接受参数 PowerShell 的位置参数
- asp.net-mvc - Azure 应用服务上的受信任根证书
- c - 运行代码后,输出始终为零
- javascript - 什么是仅使用 date-fns 设置日期的时间部分的有效方法?
- javascript - 如何将今天的日期和时间显示为上午 9 点并持续到第二天?
- android - 找不到来自非 activity_main.xml 的视图
- c# - 无论如何都无法让 AWS Lambda 到 PutObject 到 S3 在同一个账户中
- reactjs - NextJS:getInitialProps 中的 Redux thunk 调用
- rust - 如何使用 lapin 获取 AMQP 消息标头值?