【问题标题】:Browse device via OpenFileDialog and download via FTP通过 OpenFileDialog 浏览设备并通过 FTP 下载
【发布时间】:2018-10-30 14:36:37
【问题描述】:

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

这是一个代码sn-p:

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);

【问题讨论】:

  • openfiledialog 正在使用资源管理器。这将是您应该为其编写自定义对话框的内容。
  • 所以没有其他解决方案可以让我获得选定的文件名吗? ://

标签: c# .net winforms ftp openfiledialog


【解决方案1】:

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

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

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

【讨论】:

  • 谢谢!我创建了一个FTPFileDialog 并在itemView 上显示当前目录中的任何文件,具有不同的功能,如“打开文件”和“删除文件”......它工作正常。
猜你喜欢
  • 1970-01-01
  • 2016-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-18
  • 2020-05-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多