1

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.

shanabus
  • 12,989
  • 6
  • 52
  • 78
Zen3515
  • 309
  • 4
  • 12
  • does the folder IMG exist? – MUG4N Oct 16 '13 at 12:15
  • I've edited your question to remove the C# tag from the title. Read why: http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles – Tim Schmelter Oct 16 '13 at 12:15
  • My file already exists. I'm sorry I forgot to tell – Zen3515 Oct 16 '13 at 12:17
  • catch the exception to get more details: String status = ((FtpWebResponse)e.Response).StatusDescription; – MUG4N Oct 16 '13 at 12:20
  • 550 the filename directory name or volume label syntax is incorrect. Win32 error: the filename directory name or volume label syntax is incorrect. Error details: file system returned an error. End I use windows 8 Pro, IIS8.0 – Zen3515 Oct 16 '13 at 12:26
  • ok your file path is not correct check if you miss a slash somewhere – MUG4N Oct 16 '13 at 12:30
  • @MUG4N This is what show in textBox4 ftp://192.168.2.11:1919/IMG/test.png I coppy this address and paste in chorme browser I can access the file. What I wrong :( – Zen3515 Oct 16 '13 at 12:35

1 Answers1

1

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;
MUG4N
  • 19,377
  • 11
  • 56
  • 83
  • uploadto = ("ftp://" + severip + ":1919//" + "IMG/"+ username + ".png") uploadto = ("ftp://" + severip + ":1919//" + "IMG//"+ username + ".png") Give me the same error uploadto = ("ftp://ftp." + severip + ":1919//" + "IMG/"+ username + ".png") Give me new error "the remote name could not be resolved" – Zen3515 Oct 16 '13 at 12:44
  • my last idea: check your security settings in your iis: http://stackoverflow.com/questions/17471745/ftp-getresponse-error-550-file-unavailable?rq=1 – MUG4N Oct 16 '13 at 12:47
  • Sloved request.Method = WebRequestMethods.Ftp.DownloadFile; working Thanks :D sorry I can't vote up I don't have reputation enought – Zen3515 Oct 16 '13 at 12:48