【问题标题】:WebRequestMethods.Ftp to navigate to directoryWebRequestMethods.Ftp 导航到目录
【发布时间】:2010-08-18 19:55:27
【问题描述】:

我正在尝试使用 FtpWebRequest 通过 ftp 上传文件,如下所示:

ftpRequest = (FtpWebRequest)WebRequest.Create("ftp.somethong.com");

ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;

ftpRequest.Credentials = new NetworkCredential("user", "pass");

但是,当连接并上传文件时,文件会进入根目录,而我需要将其放入 /Upload 目录。

我可以创建目录,但如何在上传文件之前浏览那里?

【问题讨论】:

    标签: c# ftp ftpwebrequest


    【解决方案1】:

    您需要将目录放在用于创建请求的 URL 中,即

     ftpRequest = (FtpWebRequest)WebRequest.Create("ftp://ftp.somethong.com/Upload/filename.ext");
    

    【讨论】:

    • 尝试您的建议时:ftpRequest = (FtpWebRequest)WebRequest.Create("ftp.adftest.rightmove.com/test/upload/test.zip");无效的 URI:无法确定 URI 的格式。然后在尝试时: ftpRequest = (FtpWebRequest)WebRequest.Create("adftest.rightmove.com/test/upload/test.zip"); 无法连接到远程服务器
    • ^^ 不清除。本质上,根据您的建议,我得到 Invalid URI: The format of the URI could not be determined。尝试 .Create("adftest.rightmove.com/test/upload/test.zip"); 时,我无法连接到远程服务器。
    • 对,对不起,URI 需要一个方案 (ftp://)。
    • 如上所述,我无法连接到远程服务器,可能是 ftp 服务器上的一些权限,但该方法应该有效。最后我使用了:codeproject.com/KB/IP/ftplib.aspx
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-24
    • 2015-10-09
    • 2017-08-08
    • 1970-01-01
    • 2017-12-10
    • 1970-01-01
    相关资源
    最近更新 更多