// Xb2.NET sample showing how to connect to a secure FTP server and upload a file.
    //------------------------------------------------------------------------------------
    
    #include "xb2net.ch"
    #pragma  library ("xb2net.lib")
    
    Procedure Main( cServer, cUserID, cPassword, cPath, cShowStatus )
       Local oFtp, bCallback
       Local cServer := "ftps://thebatcave.com:1939"
       Local cUserID := "batman"
       Local cPassword := "6otHam825"
       Local cPath := "upload"
       Local cLocalFile := "D:\MyDocuments\TheJoker.doc"
       Local cRemoteFile := "TheJoker.doc"
    
       oFtp := xbFTPClient():new()
    
       SetColor("w+/n")
       // codeblock to display status/progress info in terminal window
       bCallback := {|a,b| DisplayStatus(a,b)}
    
       // set callback to see what's going on
       oFtp:SetCallBack( bCallback )
    
       // connect to FTP server
       if ! oFtp:Connect(cServer)
          Terminate("*** ERROR: Failed to connect to FTP server " + cServer)
       endif
    
       // do login
       if oFtp:Login(cUserID, cPassword)
          ? "Connected to: " + cServer
       else
          Terminate("*** ERROR: Login failed!")
       endif
    
       // get current directory
       ? "current dir =", oFtp:GetCurrentDirectory()
    
       if !empty(cPath)
          // change directory
          if ! oFtp:SetCurrentDirectory(cPath)
             Terminate( "*** ERROR: Unable to change path to: " + cPath )
          endif
    
          ? "path changed, current dir =", oFtp:GetCurrentDirectory()
       endif
    
       ShowDir( oFtp )
    
       ? "Upload file: " + cLocalFile
       if oFtp:PutFile(cLocalFile, cRemoteFile)
          ? "Transmitted:", oFtp:BytesTransferred, "bytes in", oFtp:ElapsedTime, "seconds"
       else
          Terminate("*** ERROR: Unable to upload file!")
       endif
    
       ShowDir( oFtp )
    
       oFtp:Destroy()
       Terminate("end...")
       Return
    
    Procedure DisplayStatus( nStatus, cMessage )
       Local cColor := SetColor(iif(isFTP_ERR(nStatus), "r/n", "n+/n"))
       ? nStatus, cMessage
       SetColor(cColor)
       Return
    
    Procedure Terminate( cMessage, lQuit )
       Local cColor
    
       if cMessage != NIL
          cColor := SetColor("gr+/n")
          ? cMessage
          inkey(0)
          SetColor(cColor)
       endif
       if lQuit == NIL .or. lQuit
          quit
       endif
       Return
    
    Procedure ShowDir( oFtp )
       Local aDir, cColor
    
       cColor := SetColor("g/n")
       ?
       ? "Push a key to get directory listing..."
       SetColor(cColor)
       inkey(0)
       aDir := oFtp:Directory()
       ? "dir: " + iif(Empty(aDir), "", "")
       AEval(aDir, {|x| QOut(x)})
       ?
       Return
    

    home     download     top of page