private bool FtpDirectoryExists(string dirPath, string FTPUser, string FTPPassword) { bool IsExists = true; try { FtpWebRequest request = (FtpWebRequest)WebRequest.Create(dirPath); request.Credentials = new NetworkCredential(FTPUser, FTPPassword); request.Method = WebRequestMethods.Ftp.ListDirectory; FtpWebResponse response = (FtpWebResponse)request.GetResponse(); //response.Close(); } catch (WebException ex) { IsExists = false; } return IsExists; }
public bool CheckIfFtpFileExists(string fileUri) { FtpWebRequest request = WebRequest.Create(fileUri); request.Credentials = new NetworkCredential("username", "password"); request.Method = WebRequestMethods.Ftp.GetFileSize; try { FtpWebResponse response = request.GetResponse(); // THE FILE EXISTS } catch(WebException ex) { FtpWebResponse response = ex.Response; if (FtpStatusCode.ActionNotTakenFileUnavailable == response.StatusCode) { // THE FILE DOES NOT EXIST return false; } } return true; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)