FTP在C#中创建文件夹和上传文件

Dae*_*vin 3 c# ftp ftpwebrequest

所以我试图自动上传到 ftp,但我无法让它工作。我所拥有的是(尝试创建一个文件夹):

private void button1_Click(object sender, EventArgs e)
{
    FTPUpload(txtIP.Text, txtUName.Text, txtPWord.Text);
}

private void FTPUpload(string ftpAddress, string ftpUName, string ftpPWord)
{
    FtpWebRequest ftpRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpAddress + "/AUTO_TEST_FOLDER"));
    ftpRequest.Credentials = new NetworkCredential(ftpUName, ftpPWord);
    ftpRequest.Method = WebRequestMethods.Ftp.MakeDirectory;
    WebResponse response = ftpRequest.GetResponse();
    using (var resp = (FtpWebResponse)ftpRequest.GetResponse())
    {
        MessageBox.Show(resp.StatusCode.ToString());
    }
Run Code Online (Sandbox Code Playgroud)

我不断收到未处理的 WebException “远程服务器返回错误:(550) 文件不可用(例如,找不到文件,无法访问)。” 在线WebResponse response = ftpRequest.GetResponse();

有人可以帮我吗?

我尝试了几种解决方案,包括如何使用 C# 在 ftp 服务器上创建目录?,但没有成功(即使复制/粘贴该答案并输入我的 ip/uname/pword 也没有成功)。

Dae*_*vin 5

我设法让它与:

private void FtpCreateFolder(string ftpAddress, string ftpUName, string ftpPWord)
    {
            WebRequest ftpRequest = WebRequest.Create("ftp://" + ftpAddress + "/AUTO_TEST_FOLDER");
            ftpRequest.Method = WebRequestMethods.Ftp.MakeDirectory;
            ftpRequest.Credentials = new NetworkCredential(ftpUName, ftpPWord);
    }
Run Code Online (Sandbox Code Playgroud)

我猜问题是使用FtpWebRequest ftpRequest = (FtpWebRequest)FtpWebRequest.Create(...). 无论如何,谢谢,所以,希望其他人觉得这很有用!