'
' ============================================================================
' QFTPCLIENT              EXTENDED  COMPONENT              By Jacques Philippe
'
' RQ DEMO CODE                                     Version February 12th, 2003                    
' ============================================================================
'
$INCLUDE "QFtpClient.Inc"
'
$ESCAPECHARS ON
$TYPECHECK ON
$INCLUDE "RAPIDQ.INC"
'
'
Declare Sub OnClose_frmFTP_Demo
Declare Sub OnClic_mnuDoFtp (Sender As QMenuItem)
'
Create frmFTP_Demo As QForm
    Center
    Width = 600
    height = 800
    Caption = "frmFTP_Demo V 1.0.0 " 
    AutoScroll = False
    OnClose = OnClose_frmFTP_Demo
    CREATE rchWin AS QRichEdit  ' will disply the received datas
        Align = 5
        Font.Name = "courier"    
        Font.Size = 8
        Font.Color = &H800000
        ReadOnly = True
        WordWrap = False
        ScrollBars = ssBoth
        HideSelection = False 
        PlainText = True
    END CREATE
    CREATE Main AS QMAINMENU
        CREATE mnuDoFtp AS QMENUITEM
            Caption = "&DoFtp"
            OnClick = OnClic_mnuDoFtp
        END CREATE
    END CREATE
End Create
'
Dim myFTP As QFtpClient
'
' *************************************
frmFTP_Demo.ShowModal
' *************************************
'
Sub OnClose_frmFTP_Demo
    Application.Terminate
    End
End Sub
'
' ---------------- DEMO CODE --------------------------------------------
'
Sub OnClic_mnuDoFtp (Sender)
    DefInt iTmp
    DefStr sTmp, sLine
  With myFtp
    ' Connection
    iTmp = .Connect ("hitl.washington.edu", "jkelly", "")
    rchWin.Addstrings (.ErrorMsg)
    rchWin.Addstrings (.ReadMessage)

    ' Get Current Directory
    rchWin.Addstrings ("      Current Directory : " & .GetDir)
    rchWin.Addstrings (.ErrorMsg)

    ' Upload a File
    iTmp = .PutFile ("Drive:\\LocalDir\\LocalFileName.Ext", "RemoteFileName.Ext") 
    rchWin.Addstrings (.ErrorMsg)

    ' Set Directory
    iTmp = .SetDir ("Drive:\\RemoteDir")
    rchWin.Addstrings (.ErrorMsg)

    ' Get Current Directory
    rchWin.Addstrings ("      Current Directory : " & .GetDir)
    rchWin.Addstrings (.ErrorMsg)

    ' MakeDir (No Overwrite)
    iTmp = .MakeDir ("NewRemoteDir")
    rchWin.Addstrings (.ErrorMsg)

    ' Set Directory
    iTmp = .SetDir ("NewRemoteDir")
    rchWin.Addstrings (.ErrorMsg)

    ' Get Current Directory
    rchWin.Addstrings (.ErrorMsg)
    rchWin.Addstrings ( "      Current Directory : " & .GetDir)

    ' Upload a File
    iTmp = .PutFile ("Drive:\\YourDir\\LocalFileName.Ext", "RemoteFileName.Ext") 
    rchWin.Addstrings (.ErrorMsg)

    ' Rename a File (dont overwrite)
    iTmp = .Rename ("FromRemoteName.Ext", "ToRemoteName.Ext")
    rchWin.Addstrings (.ErrorMsg)

    ' Delete a File
    iTmp = .Delete ("RemoteFileName.Ext")
    rchWin.Addstrings (.ErrorMsg)

    ' Set Directory 
    iTmp = .SetDir ("Drive:\\RemoteDir")
    rchWin.Addstrings (.ErrorMsg)

    ' Remove Directory
    iTmp = .RemoveDir ("newdir")
    rchWin.Addstrings (.ErrorMsg)

    ' Set Directory 
    iTmp = .SetDir ("d:\\")
    rchWin.Addstrings (.ErrorMsg)

    ' Get Current Directory
    rchWin.Addstrings ( "      Current Directory : " & .GetDir)
    rchWin.Addstrings (.ErrorMsg)

    ' DownLoad a File
    iTmp = .GetFile ("R_km_247", "c:\\YourDir\\Marx48", True)
    rchWin.Addstrings (.ErrorMsg)

    ' Delete A File
    iTmp = .Delete ("d:\\R_km_247")
    rchWin.Addstrings (.ErrorMsg)

    'Goto NOFILELIST
    Dim fileOut As QFileStream
    fileout.Open ("filelist.txt", fmCreate)
        sTmp = .FindFirstFile("c:\\YourDir\\*.*")
        iTmp = 1
        While sTmp <> ""
            sLine = Str$(iTmp) & "_th = " & sTmp & _
                    "\n     dosFileName = " & .dosFileName & _
                    "\n            size = " & Str$(.fileSize) &  _
                    "\n          DateUS = " & .fileDate &  _
                    "\n          DateEU = " & .FileDateEU &  _
                    "\n          TimeMs = " & .FileTimeMs &  _
                    "\n            Time = " & .FileTime & _
                    "\n        DateTime = " & Str$(.FileDateTime) & _
                    "\n      Attributes = " & Str$(.fileAttributes) & _
                    "\n   AttribAString = " & .fileAttributesAsString
            rchWin.Addstrings (sLine)
            fileOut.WriteLine (sLine)
            Inc iTmp
            sTmp = .FindNextFile
        Wend    
        rchWin.Addstrings ("End of directory")
        fileOut.WriteLine ("End of directory")
    fileOut.Close
    ' Check read only
    rchWin.Addstrings ("myFtpHandle=" & Str$(.ftpHandle))
NOFILELIST:
    ' Deconnection
    iTmp = .Close    ' Dont Forget To Close
    rchWin.Addstrings (.ErrorMsg)
    rchWin.Addstring ("\n\n   ***  I  AM  FINISHED  ***")
  End With
End Sub
'
