Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleRemove files from a Web server
KeywordsWeb, file, remove, URL, server, FTP
CategoriesUtilities, Controls, Internet
 
Set the Internet Transfer Control's URL, UserName, and Password properties. Execute the CD command to move into the proper directory. Then execute the DELETE command to delete a list of files.
 
Private Sub cmdRemove_Click()
Dim host_name As String
Dim i As Integer
Dim files As Variant
Dim file_name As String

    MousePointer = vbHourglass
    txtResults.Text = "Working"
    txtResults.SelStart = Len(txtResults.Text)
    DoEvents

    ' You must set the URL before the user name and
    ' password. Otherwise the control cannot verify
    ' the user name and password and you get the error:
    '
    '       Unable to connect to remote host
    host_name = txtHost.Text
    If LCase$(Left$(host_name, 6)) <> "ftp://" Then _
        host_name = "ftp://" & host_name
    inetFTP.URL = host_name

    inetFTP.UserName = txtUserName.Text
    inetFTP.Password = txtPassword.Text

    ' Do not include the host name here. That will make
    ' the control try to use its default user name and
    ' password and you'll get the error again.

    ' Change to the HowTo directory.
    AddMessage "CD " & txtPath.Text
    inetFTP.Execute , "CD " & txtPath.Text
    Do While inetFTP.StillExecuting()
        DoEvents
    Loop

    ' Delete the files.
    files = Split(txtFiles.Text, vbCrLf)
    For i = LBound(files) To UBound(files)
        file_name = Trim$(files(i))
        If Len(file_name) > 0 Then
            On Error GoTo NameError
            ' Delete the file.
            AddMessage "DELETE " & file_name & ".zip"
            inetFTP.Execute , "DELETE " & file_name & ".zip"
            Do While inetFTP.StillExecuting()
                DoEvents
            Loop
            AddMessage file_name & "  OK"
        End If
NameDone:
        On Error GoTo 0

    Next i

    MousePointer = vbDefault
    MsgBox "Done"
    Exit Sub

NameError:
    AddMessage file_name & "  **** ERROR ****"
    Resume NameDone
End Sub

Private Sub AddMessage(ByVal msg As String)
    txtResults.Text = txtResults.Text & vbCrLf & msg
    txtResults.SelStart = Len(txtResults.Text)
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated