I trying to check if file exists on my FTP server but I get error "The remote server returned an error: (550) File unavailable" while my file already exists I sure it wasn't happen by my permission or wrong ip or wrong user, Because I can use FileZilla to edit my file with FTPUser20, And I copy textBox4("textBox4.Text = (uploadto);") and paste in my browser I can access. Here is my code

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

please help me. My file already exists.

有帮助吗?

解决方案

You should try your code with a double slash at the end:

uploadto = ("ftp://" + severip + ":1919//" + "IMG/"+ username + ".png")

you should also try this approach:

uploadto = ("ftp://ftp." + severip + ":1919//" + "IMG/"+ username + ".png")

try to change your request method like this:

request.Method = WebRequestMethods.Ftp.DownloadFile;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top