gpt4 book ai didi

c# - FTP创建文件夹并在C#中上传文件

转载 作者:行者123 更新时间:2023-11-30 17:00:52 26 4
gpt4 key购买 nike

所以我试图自动将一些上传到 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());
}

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

有人可以帮我吗?

我尝试了几种解决方案,包括 How do I create a directory on ftp server using C#? 中的答案,但没有成功(即使复制/粘贴该答案并输入我的 ip/uname/pword 也没有成功)。

最佳答案

我设法让它工作:

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

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

关于c# - FTP创建文件夹并在C#中上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21666412/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com