Private [b]WithEvents [/b]oFTP As CFtp
Private Sub Form_Load()
Set oFTP = New CFtp
'All arguments to the Connect method is optional
'you can set them via properties instead
oFTP.Connect "ftp.mysite.com", "username", "password"
' Set the TransferType property to determent how a file
' is transfered as ASCII (converts newlines) or as Binary
oFTP.TransferType = FTP_TRANSFER_TYPE_ASCII 'or FTP_TRANSFER_TYPE_BINARY
' The UploadFile raises events while uploading
' but the call will still not return until its done.
' You can however cancel the transfer in the TransferProgress
' event if you like by setting the CancelProperty to True
oFTP.UploadFile "c:\myfile.txt", "newfile.txt"
' You can also use the PutFile method to upload a file,
' however this method does not raise any events and does not
' give you the option to cancel the transfer:
'oFTP.PutFile "c:\LocalFile.txt", "RemoteName.txt"
' To download a file simply use the DownloadFile method
' if you want the events to fire or the GetFile method if
' you are not interested in the progress.
'
' The following shows how you can list the files in the current
' remote directory into a listbox.
Dim oFile As CFtpFile
' First argument: File pattern (use * instead of *.* on Unix/Linux)
' Second argument: (Optional) NoCache
oFTP.ListDir "*", True '<- Second argument (optional): NoCache
For Each oFile In oFTP.Files
If oFile.IsDirectory Then
List1.AddItem "[" & oFile.FileName & "]"
Else
List1.AddItem oFile.FileName
End If
Next
' The CFtp class has a bunch of other method and properties such as
' MakeDir, ChangeDir, DeleteDir, DeleteFile, FileExist, GetCurrDir
' .. and so on
End Sub
Private Sub oFTP_ErrorMsg(ByVal sErr As String)
'Error messages
Debug.Print "Error: " & sErr
End Sub
Private Sub oFTP_StatusMsg(ByVal Msg As String)
'different status messages
Debug.Print Msg
End Sub
Private Sub oFTP_TransferCompleted()
'a download/upload is completed
End Sub
Private Sub oFTP_TransferProgress(ByVal nPercent As Long, _
ByVal fBytesReceived As Double, ByVal fFileSize As Double)
'You can use this event to update a progress bar or
'to give some other feedback to the user about the
'download/upload progress.
End Sub