FTP Rekursiv löschen

  • VB.NET

Es gibt 8 Antworten in diesem Thema. Der letzte Beitrag () ist von Solaris.

    FTP Rekursiv löschen

    Hey,

    Also, ich habe nochmal ein problem mit dem rekursiven löschen eines FTP Ordners.

    Was will ich erreichen?

    • Löschen eines Ordners auf meinem FTP Server, sowie alle darin enthaltene Dateien/Ordner.


    Soweit bin ich schon:

    VB.NET-Quellcode

    1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    2. Dim ftpreq As FtpWebRequest = FtpWebRequest.Create("ftp://meinserver/Testfolder")
    3. With ftpreq
    4. .Credentials = New NetworkCredential("username", "password")
    5. .Method = WebRequestMethods.Ftp.ListDirectory
    6. End With
    7. Dim sr As New StreamReader(ftpreq.GetResponse().GetResponseStream())
    8. Dim str As String = sr.ReadLine()
    9. Dim myFtpWebRequest As FtpWebRequest
    10. Dim myFtpWebResponse As FtpWebResponse
    11. While str <> Nothing
    12. myFtpWebRequest = WebRequest.Create("ftp://meinserver.net/" & str)
    13. myFtpWebRequest.Credentials = New NetworkCredential("username", "password")
    14. myFtpWebRequest.Method = WebRequestMethods.Ftp.DeleteFile
    15. myFtpWebResponse = myFtpWebRequest.GetResponse()
    16. myFtpWebResponse.Close()
    17. str = sr.ReadLine()
    18. End While
    19. sr.Close()
    20. MessageBox.Show("Deleted Folder successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
    21. End Sub


    Ich weis, FTP Daten niemals in den Quellcode, wird auch später geändert, dient hier nur zum testen?
    Wo liegt mein Fehler, was mach ich falsch?



    :wacko: ?(
    C# Developer
    Learning C++
    Lern lesen:

    VB.NET-Quellcode

    1. Dim sr As New StreamReader(ftpreq.GetResponse().GetResponseStream())
    2. Dim str As String = sr.ReadLine()


    ;)
    "Life isn't about winning the race. Life is about finishing the race and how many people we can help finish the race." ~Marc Mero

    Nun bin ich also auch soweit: Keine VB-Fragen per PM! Es gibt hier ein Forum, verdammt!
    Wenn der Fehler bei .GetResponse springt bezweifle ich das.
    While str <> Nothing

    Kannst aber mal String.Empty versuchen, ich weiß nicht ob es da einen Unterschied gibt.

    Grüße
    "Life isn't about winning the race. Life is about finishing the race and how many people we can help finish the race." ~Marc Mero

    Nun bin ich also auch soweit: Keine VB-Fragen per PM! Es gibt hier ein Forum, verdammt!