파일이 존재하는지 여부를 확인하는 코드를 작성하고 있습니다. 파일이 존재하면 WebException을 던져야합니다. 코드는 아래와 같습니다. .NET 3.5에서이 코드를 실행하면 WebException이 throw되지만 .NET 4.0을 사용하면 예외가 throw되지 않습니다. 내가 파일의 존재를 확인할 수 있도록 던져 질 예외가 싶습니다.WebException을 throw하는 코드는 .NET 3.5에서는 작동하지만 4.0에서는 작동하지 않습니다.
bool IsExists = true;
try
{
// string ftpServer = "FTP://111.111.111.111/16FebTo15Mar/Backup/MT_Backup/";
string userName = "gff";
// string filename = "sachin";
string password = "[email protected]";
string ftppath= "FTP://111.111.111.111/16FebTo15Mar/Backup/MT_Backup/bh/";
// Ftpurl + new FileInfo(EmpFldr).Name + "/";
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftppath);
request.Credentials = new NetworkCredential(userName, password);
request.Method = WebRequestMethods.Ftp.PrintWorkingDirectory;
// request.Method = WebRequestMethods.Ftp.MakeDirectory;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
IsExists = false;
}
return IsExists;
매우 확실하지만 [은'UsePassive' 속성을 변경]하지 (http://stackoverflow.com/questions/4604693/ftp-throws-webexception-only-in-net-4-0) ftprequest – V4Vendetta
예외가 여전히 throw됩니까? 보다 일반적인 예외를 포착하고 그것이 무엇인지 확인하십시오. – rikitikitik