FTP Connection Tester / INI File - Read, Write, Save & Load Example

1 post in this topic

#1 ·  Posted (edited)

Hi All,

Here is a little GUI I built a while back to learn how to use INI files to store information ( variables ) between opening and closing certain programs.

I just recently pulled it back out and cleaned it up and debugged it, if you find any bugs please kill them.:P

The FTP connection part was just so it would have purpose...B) 

To cut down on clutter there are no labels, hover mouse over to see what things are.



#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <FTPEx.au3>

Global $HostName
Global $UserName
Global $PassWord

$Form1 = GUICreate("FTP Login Credentials", 357, 162, 192, 124)
$HostNameB = GUICtrlCreateInput($HostName, 40, 24, 161, 21)
GUICtrlSetTip(-1, "Enter Hostname example: 'autoit.com'")
$UserNameB = GUICtrlCreateInput($UserName, 40, 56, 161, 21)
GUICtrlSetTip(-1, "Enter Username")
$PassWordB = GUICtrlCreateInput($PassWord, 40, 88, 161, 21)
GUICtrlSetTip(-1, "Enter Password")
$Save = GUICtrlCreateButton("Save", 232, 24, 73, 25)
GUICtrlSetTip(-1, "Saves login Info to INI File")
$Load = GUICtrlCreateButton("Load", 232, 56, 73, 25)
GUICtrlSetTip(-1, "Loads Previously Saved login Info from INI File")
$clear = GUICtrlCreateButton("Clear", 232, 88, 73, 25)
GUICtrlSetTip(-1, "Deletes any Previously saved INI Files")
$testConn = GUICtrlCreateButton("Test Connection", 132, 120, 90, 25)
GUICtrlSetTip(-1, "Test your Login Credentials")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
        Case $Load
        Case $Save
        Case $clear
        Case $testConn

Func _clearAll()
    GUICtrlSetData($HostNameB, "")
    GUICtrlSetData($UserNameB, "")
    GUICtrlSetData($PassWordB, "")
    $iniFile = @ScriptDir & "\login.ini"
    If FileExists($iniFile) Then
        MsgBox(4096, $iniFile, $iniFile & ":  Was Deleted", 2)
        MsgBox(4096, $iniFile, $iniFile & ":  Does not Exist", 2)

EndFunc   ;==>_clearAll

Func _iniLoad()

    If FileExists(@ScriptDir & "\login.ini") Then
        $HostName = IniRead(@ScriptDir & "\login.ini", "login", "HostName", "Default Value")
        $UserName = IniRead(@ScriptDir & "\login.ini", "login", "UserName", "Default Value")
        $PassWord = IniRead(@ScriptDir & "\login.ini", "login", "PassWord", "Default Value")
        GUICtrlSetData($HostNameB, $HostName)
        GUICtrlSetData($UserNameB, $UserName)
        GUICtrlSetData($PassWordB, $PassWord)
        MsgBox(16, "No File", "File Not Found")

EndFunc   ;==>_iniLoad

Func _iniSave()
    $HostName = GUICtrlRead($HostNameB)
    $UserName = GUICtrlRead($UserNameB)
    $PassWord = GUICtrlRead($PassWordB)
    IniWrite(@ScriptDir & "\login.ini", "login", "HostName", $HostName)
    IniWrite(@ScriptDir & "\login.ini", "login", "UserName", $UserName)
    IniWrite(@ScriptDir & "\login.ini", "login", "PassWord", $PassWord)

EndFunc   ;==>_iniSave

Func _testConn()

    If GUICtrlRead($HostNameB) = 0 And GUICtrlRead($UserNameB) = 0 And GUICtrlRead($PassWordB) = 0 Then
        MsgBox(16, "Input Missing", "Please Enter Login Credentials")
        Local $hOpen = _FTP_Open('MyFTP Control')
        Local $hConn = _FTP_Connect($hOpen, $HostName, $UserName, $PassWord)
        If $hConn = 0 Then
            MsgBox(0, "FTP Connection", "Connection not possible", 1)
        If $hConn > 0 Then
            MsgBox(0, "FTP Connection", "FTP Connected Successfully", 1)

        Local $Ftpc = _FTP_Close($hConn)
        Local $Ftpo = _FTP_Close($hOpen)
EndFunc   ;==>_testConn


Edited by l3ill
1 person likes this

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • RC86
      By RC86
      Afternoon, I could very well be doing this wrong so feel free to totally advise otherwise - I'm wanting to use a GUI to first display a key from within an INI file, then secondly change the INI file by using a FileSelectFolder command but then I want to see the GUI change to reflect the change I've just made.
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 437, 192, 124) $Input1 = GUICtrlCreateInput(Iniread(@WorkingDir & "\test.ini","Path","FilePath",""), 64, 80, 121, 21) $Button1 = GUICtrlCreateButton("Change", 200, 80, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $selectedFolder = FileSelectFolder("Select Log Path Directory",@WorkingDir,0) If NOT $selectedFolder = "" Then $newLogPath = IniWrite(@WorkingDir & "\test.ini","Path","FilePath",$selectedFolder) EndIf EndSwitch WEnd So 2 part question really: (1) Should I be using GUICtrlCreateInput to display my INI read from within the GUI? (2) How can I refresh the GUI to update that to read the new information I've just written to the GUI?

    • LWC
      By LWC
      I've made a program that relies on IniReadSectionNames. It reads (~3K) Autorun.inf files in the working folder and creates a GUI based on their contents.
      I made sure to revert to a default GUI upon @error.
      But someone (with Windows XP SP3 32-bit) reported to me he always gets the default menu.
      I sent him a FileRead command instead and it works! So seemingly there's no access problem to AutoRun.inf.
      In the following demo code, I always hit success, but he always ends up with semi-success:
      Local $hIniLocation = "Autorun.inf" Local $aSections = IniReadSectionNames($hIniLocation) If @error Then $aSections = FileRead($hIniLocation) if @error then msgbox(48, "Double error", "Alternative access failed too due to:" & @crlf & @error & @crlf & @extended) else msgbox(0, "Semi-success", "IniReadSectionNames failed, but alternativaly this file contains:" & @crlf & @crlf & $aSections) endif else msgbox(0, "Success", "IniReadSectionNames worked!") endif Why is that? Is there something further to check with him?
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning community!
      I was working on a script which read the content of a .ini file to retrieve the file that has to open, and, based on the value of a second key stored in the .ini file, set the window on top, minimized or maximized...
      I did something like this, but seems to not work properly...
      Could anyone please tell me what I'm doing wrong?
      Thank you  
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile_x64=prova.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> ;#include <WinAPIEx.au3> #include <Array.au3> Local $sFileConfigurazione = @ScriptDir & "\configurazione_exe.ini" If(FileExists($sFileConfigurazione)) Then Local $aSezioneIni = IniReadSection($sFileConfigurazione, "CONFIGURAZIONE_EXE") If @error Then MsgBox($MB_ICONERROR, "Errore!", "Errore durante l'apertura del file: " & @CRLF & $sFileConfigurazione & @CRLF & "Errore: " & @error) Else ; Lancio dell'applicativo indicato nel file di configurazione Local $iPID = ShellExecute($aSezioneIni[1][1]) Local $hWnd If($iPID <> 0) Then Local $aWinList = WinList() For $i = 1 To $aWinList[0][0] If(WinGetProcess($aWinList[$i][1] = $iPID)) Then $hWnd = $aWinList[$i][1] EndIf Next Switch($aSezioneIni[2][1]) Case $aSezioneIni[2][1] = "MIN" ToolTip("MIN", 0, 0) WinSetState($hWnd, WinGetTitle($hWnd), @SW_MINIMIZE) Case $aSezioneIni[2][1] = "MAX" ToolTip("MAX", 0, 0) WinSetState($hWnd, WinGetTitle($hWnd), @SW_MAXIMIZE) Case $aSezioneIni[2][1] = "TOP" ToolTip("TOP", 0, 0) WinSetOnTop($hWnd, WinGetTitle($hWnd), $WINDOWS_ONTOP) EndSwitch EndIf EndIf EndIf And the .ini file is like this:
      [CONFIGURAZIONE_EXE] PercorsoExe=Here goes the path and the .exe to execute ModalitaAperturaExe=Here goes one of the value below /* TOP Shows the windows on top */ /* MIN Shows the window minimized */ /* MAX Shows the window maximized */  
    • Xandy
      By Xandy
      Screenshot program that can upload/FTP to website/storage with hotkey.
      Features GUI to display programmable keys.

      Set the hotkeys with this function to use, and display hotkeys.
      ; hotkey_set() Parameters: ; ----------------------------------------------------------- ; $aHotkey -                The array hotkeys are stored in. This function sets the values of this array[hotkey_id][$hotkey_data] ; $dHotkey_id -             The enum for this hotkey index ; $sHotkey_description -     The label displayed to the user to represent function of hotkey ; $sHotkey_name -            The hotkey it'self.  Whatever name string you want to give the key ; $dHotkey_key -             The _IsPressed keycode ;    Keycodes AT: https://www.autoitscript.com/autoit3/docs/libfunctions/_IsPressed.htm ; $dHotkey_shift -             Shift flag 0 or 1 Default off ; $dHotkey_ctrl -             Ctrl flag 0 or 1 Default off ; $dHotkey_alt -             Alt flag 0 or 1 Default off Func hotkey_set(ByRef $aHotkey, $dHotkey_id, $sHotkey_description, $sHotkey_name, $dHotkey_key, $dHotkey_shift = 0, $dHotkey_ctrl = 0, $dHotkey_alt = 0)     $aHotkey[$dHotkey_id][$eHotkey_data_key_description] = $sHotkey_description     $aHotkey[$dHotkey_id][$eHotkey_data_key_name] = $sHotkey_name     $aHotkey[$dHotkey_id][$eHotkey_data_key] = $dHotkey_key     $aHotkey[$dHotkey_id][$eHotkey_data_shift] = $dHotkey_shift     $aHotkey[$dHotkey_id][$eHotkey_data_ctrl] = $dHotkey_ctrl     $aHotkey[$dHotkey_id][$eHotkey_data_alt] = $dHotkey_alt EndFunc   ;==>hotkey_set ; You can set your hotkeys here ; Please visit the hotkey_set() function for parameter information hotkey_set($aHotkey, $eHotkey_screenshot_ftp, "Selected Window to FTP", "F12", "7B", 0, 1, 0); F12 hotkey_set($aHotkey, $eHotkey_screenshot_disk, "Selected Window to Disk", "S", "53", 1, 1, 1); S hotkey_set($aHotkey, $eHotkey_clipboard_send, "Send Clipboard keystrokes", "F10", "79", 1, 1, 1); F10  
      Configure settings dialog:

      Screenshot Filename and Screenshot Counter, are used to create simple unique filenames that can cycle. Copy URL to clipboard option. - For linking your screenshots. The screenshot file type is for local copy only. App always uses .JPG for FTP right now, but I could add FTP screenshot file type specification.  
      Any suggestions?  Did I break anything, what did I miss?
      Package uses TTS.au3 by Beege: 
      File includes:
         - FTP_Screen.au3
         - FTPScreen.ico
         - TTS.au3 - by Beege
    • drorshem
      By drorshem
      I'm looking to create a script which will download all *.txt files from a remote FTP server.
      Once downloaded, delete all *.txt files.
      Can this be achieved using AutoIt ?