Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Check if FTP Directory EXISTS
    text
    copied!<p>I have this FTP Method that checks if a directory exists. It works fine at the start, but now, it's still returning true even if the directory does not exists. I tried many things, and set breakpoint to see what property of the response object I can use to determine whether the directory exists or not. I also searched the internet and the solutions don't seem to work for me. Here is my FTP method.</p> <pre><code>public bool directoryExists(string directory) { /* Create an FTP Request */ ftpRequest = (FtpWebRequest)FtpWebRequest.Create(host + "/" + directory); /* Log in to the FTP Server with the User Name and Password Provided */ ftpRequest.Credentials = new NetworkCredential(user, pass); /* Specify the Type of FTP Request */ ftpRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails; try { using (ftpRequest.GetResponse()) { return true; } //var response = ftpRequest.GetResponse(); //if (response != null) // return true; //else return false; } catch (Exception ex) { Console.WriteLine(ex.ToString()); return false; } /* Resource Cleanup */ finally { ftpRequest = null; } } </code></pre> <p>And here is the method that calls it and returns true even if the directory does not exist:</p> <pre><code>private string getDirectory(ref FtpClass ftp, string internalID) { string remoteSubPathDel = internalID + "\\trunk\\prod\\xml\\delete"; string remoteSubPathUpdate = internalID + "\\trunk\\prod\\xml\\update"; string remoteSubPathNew = internalID + "\\trunk\\prod\\xml\\new"; if (ftp.directoryExists(remoteSubPathDel)) return remoteSubPathDel; else if (ftp.directoryExists(remoteSubPathUpdate)) return remoteSubPathUpdate; else if (ftp.directoryExists(remoteSubPathNew)) return remoteSubPathNew; else return String.Empty; } </code></pre> <p>Hope someone can help. Thanks! :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload