l3ill

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.

cya,

Bill

#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")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Load
            _iniLoad()
        Case $Save
            _iniSave()
        Case $clear
            _clearAll()
        Case $testConn
            _testConn()
    EndSwitch
WEnd

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

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)
    Else
        MsgBox(16, "No File", "File Not Found")
    EndIf

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")
    Else
        _iniSave()
        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)
        EndIf
        If $hConn > 0 Then
            MsgBox(0, "FTP Connection", "FTP Connected Successfully", 1)
        EndIf

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

 

Edited by l3ill
format
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

    • 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?
      Autorun.inf
    • 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: 
       
      FTP_Screen.zip
      File includes:
         - FTP_Screen.au3
         - FTPScreen.ico
         - TTS.au3 - by Beege
    • drorshem
      By drorshem
      Hi,
      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 ?
    • DagSa
      By DagSa
      I have some problem to make my ini-file work properly. Purpose is to install program at windows 7 - 10 but think it work at XP also.
       I have included a fragment of code, but all my errors are there. It should be run by user privilege.
      The test code point out what is not working:
      Code is create a directory in %appdata%, and create a ini-file if not there. (This write of file work!)
      When change the settings only one of the two parameters are changed. One value should be changed (don't work), and the other should be added (work!). Editing manually by notepad does not allow to save it.  I want the code to be able to change everything in ini-file.
      1. First of all, the ini-file is not writeable by user when look at file properties and also directory properties. Any way to change this?
      2. Is %appdata% wrong directory? I want all user to have access to the settings but its enough if only by control of the program.
      It make me crazy its writeable sometimes, and sometimes not. Any ideas?
      /Dag
      AppData_INI-test.au3