【发布时间】:2013-10-24 12:54:39
【问题描述】:
我试图检查我的 FTP 服务器上是否存在文件,但我收到错误“远程服务器返回错误:(550) 文件不可用”,而我的文件已经存在我确定这不是我的许可或错误的 ip或错误的用户,因为我可以使用 FileZilla 通过 FTPUser20 编辑我的文件,然后我复制 textBox4("textBox4.Text = (uploadto);") 并粘贴到我可以访问的浏览器中。
这是我的代码
public bool FtpDirectoryExists(string directoryPath, string ftpUser, string ftpPassword)
{
bool IsExists = true;
try
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(directoryPath);
request.Credentials = new NetworkCredential(ftpUser, ftpPassword);
request.Method = WebRequestMethods.Ftp.PrintWorkingDirectory;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
IsExists = false;
MessageBox.Show(ex.Message);
}
return IsExists;
}
private void button6_Click(object sender, EventArgs e)
{
string uploadto;
severip = textBox1.Text;
username = textBox2.Text;
password = textBox3.Text;
uploadto = ("ftp://" + severip + ":1919/" + "IMG/"+ username + ".png");
textBox4.Text = (uploadto);
//check if exists
bool result = FtpDirectoryExists(uploadto, "FTPUser20", "12345");
}
请帮助我。我的文件已经存在。
【问题讨论】:
-
IMG文件夹是否存在?
-
我已编辑您的问题以从标题中删除 C# 标记。阅读原因:meta.stackexchange.com/questions/19190/…
-
我的文件已经存在。对不起,我忘了告诉
-
捕获异常以获取更多详细信息:String status = ((FtpWebResponse)e.Response).StatusDescription;
-
550 文件名目录名或卷标语法不正确。 Win32 错误:文件名目录名或卷标语法不正确。错误详情:文件系统返回错误。完我用的是windows 8 Pro,IIS8.0
标签: c# .net forms ftp file-exists