home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Object = "{48E59290-9880-11CF-9754-00AA00C00908}#1.0#0"; "MSINET.OCX"
- Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
- Begin VB.Form frmFTPBrowse
- BorderStyle = 1 'Fixed Single
- Caption = "FTP Browser"
- ClientHeight = 4155
- ClientLeft = 45
- ClientTop = 330
- ClientWidth = 5040
- LinkTopic = "Form1"
- MaxButton = 0 'False
- ScaleHeight = 4155
- ScaleWidth = 5040
- StartUpPosition = 3 'Windows Default
- Begin VB.TextBox txtContents
- Height = 3735
- Left = 120
- MultiLine = -1 'True
- ScrollBars = 2 'Vertical
- TabIndex = 2
- Top = 360
- Width = 4815
- End
- Begin VB.Timer tmrSaveFile
- Enabled = 0 'False
- Interval = 10
- Left = 3480
- Top = 4560
- End
- Begin MSComDlg.CommonDialog dlgSave
- Left = 2160
- Top = 4440
- _ExtentX = 847
- _ExtentY = 847
- _Version = 393216
- FontSize = 1.17491e-38
- End
- Begin InetCtlsObjects.Inet inetBrowse
- Left = 2760
- Top = 4440
- _ExtentX = 1005
- _ExtentY = 1005
- _Version = 393216
- Protocol = 2
- RemotePort = 21
- URL = "ftp://"
- End
- Begin VB.TextBox txtAddress
- Height = 285
- Left = 840
- TabIndex = 1
- Top = 0
- Width = 4095
- End
- Begin VB.Label Label1
- Caption = "&Address:"
- Height = 255
- Left = 120
- TabIndex = 0
- Top = 0
- Width = 735
- End
- Attribute VB_Name = "frmFTPBrowse"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- Dim mstrTempDir As String
- Dim mstrDir As String
- 'API function
- Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" _
- (ByVal nBufferLength As Long, _
- ByVal lpBuffer As String) As Long
- 'Get Windows temporary file path
- Private Sub Form_Load()
- Dim lngLen As Long
- lngLen = 144
- mstrTempDir = Space(lngLen)
- lngLen = GetTempPath(lngLen, mstrTempDir)
- mstrTempDir = Left(mstrTempDir, lngLen)
- End Sub
- Private Sub txtAddress_KeyPress(KeyAscii As Integer)
- If KeyAscii = Asc(vbCr) Then
- 'Eat keystroke
- KeyAscii = 0
- 'Select text
- txtAddress.SelStart = 0
- txtAddress.SelLength = Len(txtAddress)
- On Error GoTo errOpenURL
- 'Set FTP address to view
- inetBrowse.URL = txtAddress
- 'Get directory
- inetBrowse.Execute , "Dir "
- txtAddress = inetBrowse.URL
- End If
- Exit Sub
- errOpenURL:
- Select Case Err.Number
- Case icBadUrl
- MsgBox "Bad address. Please reenter."
- Case icConnectFailed, icConnectionAborted, _
- icCannotConnect
- MsgBox "Unable to connect to network."
- Case icInetTimeout
- MsgBox "Connection timed out."
- Case icExecuting
- 'Cancel previous request
- inetBrowse.Cancel
- 'Check whether cancel worked
- If inetBrowse.StillExecuting Then
- Caption = "Couldn't cancel request."
- 'Resubmit current request
- Else
- Resume
- End If
- Case Else
- Debug.Print Err.Number, Err.Description
- End Select
- End Sub
- Private Sub txtContents_DblClick()
- 'Browse selected directory
- If txtContents.SelLength Then
- 'If selection is a directory
- If Right(txtContents.SelText, 1) = "/" Then
- 'Add selected item to address
- txtAddress = txtAddress & "/" & _
- Left(txtContents.SelText, _
- txtContents.SelLength - 1)
- 'Trap errors (important!)
- On Error GoTo errBrowse
- 'Show directory
- mstrDir = Right(txtAddress, Len(txtAddress) _
- - Len(inetBrowse.URL))
- inetBrowse.Execute , "Dir " & mstrDir & "/*"
- 'Otherwise, it's a file, so retrieve it
- Else
- Dim strFilename
- 'Build pathname of file
- mstrDir = Right(txtAddress, Len(txtAddress) _
- - Len(inetBrowse.URL)) & "/" & _
- txtContents.SelText
- mstrDir = Right(mstrDir, Len(mstrDir) - 1)
- strFilename = mstrDir
- Do
- strFilename = Right(strFilename, _
- Len(strFilename) - InStr(strFilename, "/"))
- Loop Until InStr(strFilename, "/") = 0
- 'Retrieve file
- inetBrowse.Execute , "Get " & mstrDir & _
- " " & mstrTempDir & strFilename
- End If
- End If
- Exit Sub
- errBrowse:
- If Err = icExecuting Then
- 'Cancel previous request
- inetBrowse.Cancel
- 'Check whether cancel worked
- If inetBrowse.StillExecuting Then
- Caption = "Couldn't cancel request."
- 'Resubmit current request
- Else
- Resume
- End If
- Else
- 'Display error
- Debug.Print Err & " " & Err.Description
- End If
- End Sub
- Private Sub inetBrowse_StateChanged(ByVal State As Integer)
- Select Case State
- Case icError
- Debug.Print inetBrowse.ResponseCode & " " & _
- inetBrowse.ResponseInfo
- Case icResolvingHost, icRequesting, icRequestSent
- Caption = "Searching..."
- Case icHostResolved
- Caption = "Found."
- Case icReceivingResponse, icResponseReceived
- Caption = "Receiving data."
- Case icResponseCompleted
- Dim strBuffer As String
- 'Get data
- strBuffer = inetBrowse.GetChunk(1024)
- 'If data is a directory, display it
- If strBuffer <> "" Then
- Caption = "Completed."
- txtContents = strBuffer
- Else
- Caption = "File saved in " & _
- mstrTempDir & "."
- End If
- Case icConnecting, icConnected
- Caption = "Connecting."
- Case icDisconnecting
- Case icDisconnected
- Case Else
- Debug.Print State
- End Select
- End Sub
-