Results 1 to 3 of 3

Thread: [RESOLVED] [2.0][2005] FTPWebrequest RemoveDirectory

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Location
    Bonny Scotland
    Posts
    141

    Resolved [RESOLVED] [2.0][2005] FTPWebrequest RemoveDirectory

    Hi all,

    I have been working on an app, part of which connects to a FTP site. I have code working to listdirectories, download and upload files. What i now want to do is delete directories from the FTP server once i have finished with them. I have written this code which is based on the delete file code found on the MSDN site:

    Code:
    public bool DeleteDirectoryOnServer(Uri serverUri)
            {
                // The serverUri parameter should use the ftp:// scheme.
                // It contains the name of the server file that is to be deleted.
                // Example: ftp://contoso.com/someFile.txt.
                // 
    
                try
                {
                    if (serverUri.Scheme != Uri.UriSchemeFtp)
                {
                    return false;
                }
                // Get the object used to communicate with the server.
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri);
                request.Method = WebRequestMethods.Ftp.RemoveDirectory;
                request.Credentials = m_networkcred;
    
                FtpWebResponse response = (FtpWebResponse)request.GetResponse();
    
                Debug.Print(response.StatusCode.ToString());
    
                Debug.Print("Delete status: {0}", response.StatusDescription);
                response.Close();
                return true;
                }
                catch (Exception ex)
                {
                    Debug.Print(ex.Message);
                    return false;
                }
    
                
            }
    When running the code i get the following error:

    The remote server returned an error: (550) File unavailable (e.g., file not found, no access).

    Could anyone shed some light on why this could be happening? I know the directory is there. There is also very little information available on the RemoveDirectory webrequestmethod online.

    All help is greatly appreciated.

    Thanks,

    Grant

    RESOLUTION:

    I found a resolution for the problem. It appears i can only remove empty directories. I'll need to loop through the contents and delete any files before removing the folder.
    Last edited by MadCatVB; Jul 5th, 2006 at 10:29 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width