Results 1 to 4 of 4

Thread: [RESOLVED] Deleting a file from an FTP site (am I doing it correctly)

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    10

    Resolved [RESOLVED] Deleting a file from an FTP site (am I doing it correctly)

    Hi,

    I currently have the following portion of code below, which deletes a file
    "solarradiationchart.png" from an FTP site, from within my program.

    But a couple of users are having problems with my program which I think I have
    pinpointed to this portion of code, as the other code that runs after
    it does not get processed.

    Therefore I have two questions below, which I hope someone can answer.

    1.
    Is there additional code that I will need to add to handle if the file does not exist
    on the FTP server? or is the code OK as it is?

    2.
    Also should I be using "response.Dispose()" or something similar to fully close and exit out cleanly?
    I did try "response.Dispose()" but VB would not allow it.

    As I am still very much learning on how to working with FTP sites from within VB.NET, therefore
    if it is possible could someone show me what code I should add and where, it would be much appreciated.

    Code:
    If CheckBox2.Checked = False Then
    
        'Delete "solarradiationchart.png" on FTP server if it exists
        Dim request As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create("ftp://" + FTP_URL + "solarradiationchart.png"), System.Net.FtpWebRequest)
        request.Credentials = New System.Net.NetworkCredential(FTP_UserName, FTP_Password) '// put username and password in here.
        request.Method = System.Net.WebRequestMethods.Ftp.DeleteFile
    
        Dim response As FtpWebResponse = request.GetResponse
        Console.WriteLine("Delete status: {0}", response.StatusDescription)
        response.Close()
    
    End If
    FYI.
    I am also going to add a "Try and Catch" to the code to see if I can find out
    what the error is which will also hopefully help.

  2. #2
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Re: Deleting a file from an FTP site (am I doing it correctly)

    Is there additional code that I will need to add to handle if the file does not exist
    on the FTP server? or is the code OK as it is?
    How about checking the file first if it exists then perform deletion if found?
    http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx

    or have a look at this implementation:
    http://www.codeproject.com/Tips/1636...-an-FTP-server
    Last edited by KGComputers; Dec 9th, 2013 at 12:32 PM.
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    10

    Re: Deleting a file from an FTP site (am I doing it correctly)

    KGComputers,

    Thanks for your advice and links

    I have now added the "File Checking Function" to my code and so far
    all seems to be working correctly without the previous error.

    All the best

    Mark

  4. #4
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Re: Deleting a file from an FTP site (am I doing it correctly)

    Mark,

    Welcome! Kindly mark this thread as resolved...

    Greg
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

Tags for this Thread

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