ftp check if exist

private static bool CheckIfFileExistsOnServer(string fileName)
        {
            var request = (FtpWebRequest)WebRequest.Create("url" + fileName);
            request.Credentials = new NetworkCredential(loginFtp, passwordFtp);
            request.Method = WebRequestMethods.Ftp.GetFileSize;

            try
            {
                FtpWebResponse response = (FtpWebResponse)request.GetResponse();
                return true;
            }
            catch (WebException ex)
            {
                FtpWebResponse response = (FtpWebResponse)ex.Response;
                if (response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
                    return false;
            }
            return false;
        }
Поделиться
Отправить
 222   11 мес   c#
← Ctrl