Проверить существует ли файл на ftp сервере

code: #cpp
bool CheckIfFtpFileExists(String^ ftp,String^pic)
{
        Uri^ ourUri = gcnew Uri( String::Concat(ftp,pic) );
    FtpWebRequest^ request = dynamic_cast<FtpWebRequest^>(WebRequest::Create( ourUri ));
   request->Method = WebRequestMethods::Ftp::GetFileSize;
 
    try
    {
        FtpWebResponse^ response = dynamic_cast<FtpWebResponse^>(request->GetResponse());
        //THE FILE EXISTS
                listBox1->Items->Add(String::Concat(" response.StatusCode         ",response->StatusCode));
                listBox1->TopIndex = listBox1->Items->Count - 1;
                listBox1->Items->Add(String::Concat(" response.StatusDescription         ",response->StatusDescription));
                listBox1->TopIndex = listBox1->Items->Count - 1;
                listBox1->Items->Add(String::Concat(pic," Уже существует на сервере "));
                          listBox1->TopIndex = listBox1->Items->Count - 1;
 
    } catch(WebException^ ex)
    {
                 FtpWebResponse^ response = dynamic_cast<FtpWebResponse^>(ex->Response);
                 listBox1->Items->Add(String::Concat(" response->StatusCode ",response->StatusCode));
                          listBox1->TopIndex = listBox1->Items->Count - 1;
                listBox1->Items->Add(String::Concat(" response.StatusDescription ",response->StatusDescription));
                listBox1->TopIndex = listBox1->Items->Count - 1;
                 //Console.WriteLine("Delete status: {0}",response.StatusDescription);  
        if (FtpStatusCode::ActionNotTakenFileUnavailable == response->StatusCode)
        {
            // THE FILE DOES NOT EXIST
            return false;
        }
     }
     return true;
}
Поделиться:

Похожие статьи: