Jump to content

FTP not disconnecting


l3ill
 Share

Go to solution Solved by l3ill,

Recommended Posts

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

Link to comment
Share on other sites

  • Solution

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

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

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

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...