【问题标题】:How to download files from ftp to local directory using C#?如何使用 C# 将文件从 ftp 下载到本地目录?
【发布时间】:2023-03-09 11:49:01
【问题描述】:

您好,我正在使用以下代码,但它给出了错误

 using (WebClient ftpClient = new WebClient())
        {
            ftpClient.Credentials = new System.Net.NetworkCredential("username", "password");
            ftpClient.DownloadFile("ftp://path.com/Business Plan.docx", "D:\\Folder\test.docx");
        }

但我收到错误路径中存在非法字符

我不明白该怎么做。

【问题讨论】:

    标签: ftp webclient credentials transfer


    【解决方案1】:

    这个字符串:

    "D:\\Folder\test.docx"
    

    将斜杠 ('\') 视为转义字符 - 请改用:

    @"D:\Folder\test.docx"
    

    或者(更混乱),双重转义被视为文字斜线:

    "D:\\Folder\\test.docx"
    

    【讨论】:

    • 如果您使用@ 前缀,那么您还应该删除'文件夹'之前的额外\
    猜你喜欢
    • 2019-03-29
    • 1970-01-01
    • 2013-12-29
    • 2018-07-18
    • 2013-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多