Sign in to follow this  
Followers 0
l3ill

FTP not disconnecting

10 posts in this topic

I have been using this little GUI for some time now, succesfully I might add. And was getting ready to post it as a snippet so I cleaned it up a bit and tested it and lo and behold a little mistake.

 

After clicking the Clear button which deletes the ini and clears the controls of any login information, the test connection still connects.

I have to assume that this means the variables are still carrying the data somehow soI tried setting them all to "" but that didnt work either.

 

Any help is appreciated.

Bill

 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <FTPEx.au3>
Local $HostName
Local $UserName
Local $PassWord
Local $testConn
$Form1 = GUICreate("FTP Login Credentials", 357, 162, 192, 124)
$HostNameB = GUICtrlCreateInput($HostName, 40, 24, 161, 21)
$UserNameB = GUICtrlCreateInput($UserName, 40, 56, 161, 21)
$PassWordB = GUICtrlCreateInput($PassWord, 40, 88, 161, 21)
$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()
                $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)
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()
                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)


EndFunc   ;==>_testConn

Share this post


Link to post
Share on other sites



The first three vars in the script holds that data, right?


Make yourself sheep and the wolves will eat you - Benjamin Franklin

Share this post


Link to post
Share on other sites

Perhaps a check at the top of _testConn()

If $HostName = '' Then Return


Make yourself sheep and the wolves will eat you - Benjamin Franklin

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Nope, that didn't work Thanks anyway.

I did find a workaround by letting it load the default empty values at the end of the _clearAll() function.

I guess you have to overwrite them because as mentioned above $HostName = "" didnt work...

Still would like to know what the deal was though...

Here is the fix for future searchers:

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
_iniLoad()

EndFunc   ;==>_clearAll
Edited by l3ill

Share this post


Link to post
Share on other sites

Or

$HostName = ''

$UserName = ''

$PassWord = ''


Make yourself sheep and the wolves will eat you - Benjamin Franklin

Share this post


Link to post
Share on other sites

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

Local $HostName
Local $UserName
Local $PassWord

$Form1 = GUICreate("FTP Login Credentials", 357, 162, 192, 124)
$HostNameB = GUICtrlCreateInput($HostName, 40, 24, 161, 21)
$UserNameB = GUICtrlCreateInput($UserName, 40, 56, 161, 21)
$PassWordB = GUICtrlCreateInput($PassWord, 40, 88, 161, 21)
$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
    $HostName = ""
    $UserName = ""
    $PassWord = ""
EndFunc ;==>_clearAll

Func _iniLoad()
    $HostName = IniRead(@ScriptDir & "\login.ini", "login", "HostName", "")
    $UserName = IniRead(@ScriptDir & "\login.ini", "login", "UserName", "")
    $PassWord = IniRead(@ScriptDir & "\login.ini", "login", "PassWord", "")
    GUICtrlSetData($HostNameB, $HostName)
    GUICtrlSetData($UserNameB, $UserName)
    GUICtrlSetData($PassWordB, $PassWord)
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 $HostName = "" Then Return
    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)
EndFunc ;==>_testConn


Make yourself sheep and the wolves will eat you - Benjamin Franklin

Share this post


Link to post
Share on other sites

In what way?

I might have been a bit presumptuous on your _iniLoad() function.

Are you placing real login data on the IniRead, 4th parameter, in the event the ini doesn't exist?

If you are, thats should be easy to fix.

Anyways, I gotta run, good luck to you.


Make yourself sheep and the wolves will eat you - Benjamin Franklin

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
Sign in to follow this  
Followers 0