Jump to content

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


l3ill
 Share

Recommended Posts

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
Link to comment
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
 Share

×
×
  • Create New...