JaapFresco

Troubleshooting: Function runs multiple times without apparant cause

1 post in this topic

I've written a small script that checks if files are changed and if so, uploads those files to a FTP-server. No rocket science and it works fine. With one exception: it seems that the function that actually uploads the files runs multiple times in a row, without an apparant cause. 

This is the function that checks wether or not the files have changed (filenames are read from an ini-file earlier):

Func Start_OnChange ()

    $StartSync = "False"
    $FileChanged = "False"
    if $files2Ftp = "[*]" Then
        ErrorWhileOperating($errOnChangePutDir)
    Else
        
        Local $ftpFiles = StringSplit($files2Ftp, ",")
        For $a = 1 to $ftpFiles[0]
            $fileTimeTmp = FileGetTime($localPath & "\" & $ftpFiles[$a],  $FT_MODIFIED, 1)
            if $arrFileTime[$a] <> $fileTimeTmp Then
                $FileChanged = "True"
                $arrFileTime[$a] = $fileTimeTmp
            EndIf
        Next

        $fileTimeTmp = ""

        if $FileChanged = "True" Then

            _WriteToLog("0", $ntInformation, $ntFileHasChanged)
            UploadFiles()


        EndIf

    EndIf
    $FileChanged = "False"
    $fileTimeTmp = ""
    ReDim $ftpFiles[0]
    $StartSync = "True"
EndFunc

 

If the files have changed, UploadFiles() is called:

Func UploadFiles ()

    Local $hOpen = _FTP_Open($ntSWName)
    Local $hConn = _FTP_Connect($hOpen, $ftpHost, $ftpUser, $ftpPasswd, Number($IsPassive), $ftpPort, $INTERNET_SERVICE_FTP, $INTERNET_FLAG_TRANSFER_ASCII)
    If @error Then
        ErrorWhileOperating($errFTPConn)
    Else
        if $Notify = "True" then
            TrayTip($ntSWName & $Version, $ntSyncingToRemoteLocPre & $SetName & $ntSyncingToRemoteLocPost, 2)
        EndIf

        if $files2Ftp = "[*]" Then
            _WriteToLog("0", $ntInformation, $ntUploadingToRemotePath & $remotePath)

            _FTP_DirPutContents($hConn, $localPath, $remotePath, 1)

            If @Error Then
                _WriteToLog("1", $errError, $errUploadFailed)

            else
                _WriteToLog("0", $ntInformation, $ntUploadSucceeded)
            EndIf
        Else
            Local $ftpFiles = StringSplit($files2Ftp, ",")
            For $i = 1 to $ftpFiles[0]
                _WriteToLog("0", $ntInformation, $ntUploadSingleFile & $ftpFiles[$i])
                 _FTP_FilePut($hConn, $localPath & "\" & $ftpFiles[$i], $remotePath & "/" & $ftpFiles[$i])
                If @Error Then
                    _WriteToLog("1", $errError, $errUploadFailed)
                else
                    _WriteToLog("0", $ntInformation, $ntUploadSucceeded)
                EndIf
            Next
        EndIf
    EndIf
    Local $iFtpc = _FTP_Close($hConn)
    Local $iFtpo = _FTP_Close($hOpen)
    Local $hOpen = ""
    Local $hConn = ""

EndFunc

 

The logfile (function _WriteToLog) shows multiple uploads within seconds from eachother. I cannot for the life of me find the error. Also, Start_OnChange() is called from a timer:

While 1
    if $StartSync = "True" then
        _TimerUpdate($RunFuncTimer)
    EndIf

    Switch TrayGetMsg()
        Case $trayShowWindow
            _log_Display($hGUI)

        Case $trayStartSync
            WhichTrigger()

        Case $trayExit
            _WriteToLog("0", $ntInformation, $ntSyncStopped)
            _Log_Shutdown()
            ExitLoop

    EndSwitch


WEnd

 

I hope one of you can give a hint, because I'm getting frustrated :-) 

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