User Tools

Site Tools


k19:k19.1:k19.1.3:k19.1.3.3:start

19.1.3.3 Use Profile Manager

The Profile Manager is a stand-alone programme used only for managing profiles in an application's configuration file. The application reads in the data of a profile selected in the profile manager or of the profile last used, evaluates it and assigns it internally to variables or component properties as a value. In this way, only one programme accesses the configuration file with the profiles. The profile manager must always be seen in the context of the application that uses it. The application must be able, with the help of the classes Settings or SettingsP (for Gambas 2), to call the profile manager at the first start and create a first profile or read out the data of the last used profile. Therefore, you can work with the SettingsP/Settings class in the way presented in examples 1 and 2.

In the following section, you will be presented with an FTP client that uses the described profile manager. The FTP client is suitable to illustrate the use of the profile manager to you! Please note that the FTP client only demonstrates the reading of the remote directory under the selected profile from 2 publicly accessible FTP servers:

FTP-Client

Figure 19.1.3.1: FTP Client with Profile Manager

19.1.3.3.1 Profile Manager

For your test programme, you can of course also enter your data in a new profile if you have your own FTP account.

The source code is only given here for the procedures that illustrate the interaction of the profile manager and FTP client as an application. The complete implementation can be found in the project FTPC-Profiles for Gambas 2. The changes for Gambas 3 are minor and have already been presented. You can also write more data - here the AutoConnect details - into the configuration file for the application and read it out if you think it is necessary, as a glance at the configuration file used and a second at the source code snippet show:

# Profile für einen FTP-Client
[AutoConnect]
AutoConnect=-1

[LastProfil]
LastProfilName="FH-HANNOVER"

[P_FH-HANNOVER]
FTPServerName="ftp.fh-hannover.de"
FTPUserName="anonymous"
FTPUserPassword="wer@ist.da"
FTPInitialDirRemote="pub/dos/tcpip"

[P_UNI-ERLANGEN]
FTPServerName="ftp.uni-erlangen.de"
FTPUserName="anonymous"
FTPUserPassword="wer@ist.da"
FTPInitialDirRemote="pub"

The following section shows the source code extract of the FTPC-Profile application:

' Gambas class file
 
PUBLIC ftpSettings AS SettingsP ' ---> Gambas 2
...
 
PUBLIC SUB Form_Open()
  FMain.Center
  FMain.Border = 1
  btnFileUpLoad.Enabled = FALSE
  btnFileDownLoad.Enabled = FALSE
  bFinishedFlag = FALSE
  oFTPClient.Timeout = 5
' ---> GB2; GB3 ---> ... AS NEW Settings
  ftpSettings = NEW SettingsP(Application.Path &/ "Profils/profils.conf", "Profile für einen FTP-Client")
 
  IF ftpSettings["LastProfil/LastProfilName"] = NULL THEN
     Message.Info("Es existiert kein Profil für das Client-Programm!")
     FProfilManager.ShowModal()
  ELSE
     GetProfilValues(ftpSettings["LastProfil/LastProfilName"])
     FileChooser1.Dir = FileChooser1.Dir &/ InitialDirLocal
     cboxAutoConnect.Value = ftpSettings["AutoConnect/AutoConnect", FALSE]
     IF cboxAutoConnect.Value = TRUE THEN
        ConnectToFTPServer()
     ENDIF
  ENDIF
END
 
PUBLIC SUB GetProfilValues(sProfilName AS String)
  sProfilName = "P_" & sProfilName
  FTPServerName = ftpSettings[sProfilName & "/FTPServerName"]
  FTPUserName = ftpSettings[sProfilName & "/FTPUserName"]
  FTPUserPassword = ftpSettings[sProfilName & "/FTPUserPassword"]
  InitialDirLocal = ftpSettings[sProfilName & "/FTPInitialDirLocal"]
  InitialDirRemote = ftpSettings[sProfilName & "/FTPInitialDirRemote"]
  FMain.Text = "FTP-Client mit Profil: " & Mid(sProfilName, 3)
  txtRemoteDirectory.Text = FTPServerName &/ InitialDirRemote
END
 
...
 
PUBLIC SUB btnProfilManagerShow_Click()
  FProfilManager.ShowModal
  ftpSettings.Reload()
  IF ftpSettings["LastProfil/LastProfilName"] = NULL THEN
     FProfilManager.ShowModal()
  ELSE
     GetProfilValues(ftpSettings["LastProfil/LastProfilName"])
     FileChooser1.Dir = User.Home &/ InitialDirLocal
     txtRemoteDirectory.Text = FTPServerName &/ InitialDirRemote
     txaRemote.Clear()
  ENDIF
END
 
PUBLIC SUB Form_Close()
   ftpSettings["AutoConnect/AutoConnect"] = cboxAutoConnect.Value
END
 
PUBLIC SUB btnClose_Click()
  IF oFTPClient.Status > 0 THEN oFTPClient.Close()
  FMain.Close()
END

As long as you test the programme FTF-Client with Profile Manager (project FTPC-Profile) in the IDE, you will see the connection protocol between FTP server and FTP client in the console, which shows interesting details. It can then be interpreted well if you have read RFC 959 on File Transfer Protocol (FTP) - published on the website http://www.faqs.org/rfcs/rfc959.html.

19.1.3.3 Download

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k19/k19.1/k19.1.3/k19.1.3.3/start.txt · Last modified: 13.10.2023 by emma

Page Tools