Sign in to follow this  
Followers 0
TecGuy

Array error: (39) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.

4 posts in this topic

This is the first array I have ever used. I know this is probabily something very easy but I just cannot seem to grasp the complete concept of how an array works.

The error is: (39) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

I am currently working with 13 files on the ftp site and probabily 15 local. I would like to use this script and vary the number of files each time it is run.

I have searched the forum and cant seem to find a solution

#include <FTPEx.au3>
$server = 'ftp.ftp.net'
$username = 'name'
$pass = 'Pass'

$Open = _FTP_Open('MyFTP Control')
$Conn = _FTP_Connect($Open, $server, $username, $pass)
Local $h_Handle
$aFile = _FTP_FindFileFirst($Conn, '/Backup/bin/', $h_Handle)
;ConsoleWrite('$Filename = ' & $aFile[10] & ' attribute = ' & $aFile[1] & '  -> Error code: ' & @error & ' extended: ' & @extended & @CRLF)
$dirset = _FTP_DirSetCurrent($Conn, '/Backup/bin/')
;ConsoleWrite('$dirset = ' & $dirset & '  -> Error code: ' & @error & ' extended: ' & @extended & @CRLF)
$RemoteFile = _FTP_FileGetSize($Conn, $aFile[10])
;ConsoleWrite('$Filename = ' & $aFile[10] & ' size = ' & $RemoteFile & '  -> Error code: ' & @error & ' extended: ' & @extended & @CRLF)
$LocalFile = FileGetSize("C:\Config.Msi\Backup\bin\" & $aFile[10])
    Local $Err, $Message
;ConsoleWrite('$Message = ' & $Message & ' err = ' & $Err & '  -> Error code: ' & @error & ' extended: ' & @extended & @CRLF)
;MsgBox(0, 'Remote not Exist', $RemoteFile & " , " & $LocalFile)
If $RemoteFile = 0 Then
    MsgBox(0, 'Match1', $aFile[10], "C:\Config.Msi\Backup\bin\" & $aFile[10])
    FileDelete("C:\Config.Msi\Backup\bin\" & $aFile[10])
EndIf
;MsgBox(0, 'Match', $RemoteFile & " , " & $LocalFile)
If $RemoteFile = $LocalFile Then
    Else
    FileDelete("C:\Config.Msi\Backup\bin\" & $aFile[10])
    ;MsgBox(0, 'Match2', $aFile[10], "C:\Config.Msi\Backup\bin\" & $aFile[10])
    _FTP_FileGet($Conn, $aFile[10], "C:\Config.Msi\Backup\bin\" & $aFile[10])
EndIf
$RemoteFile = _FTP_GetLastResponseInfo($Err, $Message) ; error =  Contrib: Not a regular file
Do
    $aFile = _FTP_FindFileNext($h_Handle)
    ConsoleWrite('$FilenameNext1 = ' & $aFile[10] & ' attribute = ' & $aFile[1] & '  -> Error code: ' & @error & @CRLF)
    $RemoteFile = _FTP_FileGetSize($Conn, $aFile[10])
    ConsoleWrite('$Filename = ' & $aFile[10] & ' size = ' & $RemoteFile & '  -> Error code: ' & @error & ' extended: ' & @extended & @CRLF)
    $LocalFile = FileGetSize("C:\Config.Msi\Backup\bin\" & $aFile[10])
    ;MsgBox(0, 'Match3', $RemoteFile & " , " & $LocalFile)
If $RemoteFile = $LocalFile Then
    Else
    FileDelete("C:\Config.Msi\Backup\bin\" & $aFile[10])
    MsgBox(0, 'Match2', $aFile[10], "C:\Config.Msi\Backup\bin\" & $aFile[10])
    _FTP_FileGet($Conn, $aFile[10], "C:\Config.Msi\Backup\bin\" & $aFile[10])
EndIf
    Local $Err, $Message
    $RemoteFile = _FTP_GetLastResponseInfo($Err, $Message) ; error =  Contrib: Not a regular file
    ConsoleWrite('$Message = ' & $Message & ' err = ' & $Err & '  -> Error code: ' & @error & ' extended: ' & @extended & @CRLF)
;MsgBox(0, 'Remote not Exist', $RemoteFile & " , " & $LocalFile)
Until $aFile = ""
;MsgBox(0, 'Match', $SyncNewSize & " , " & $SyncSize)
    $FindClose = _FTP_FindFileClose($h_Handle)
    $Ftpc = _FTP_Close($Open)

Thanks in advance for any help I can get.

Share this post


Link to post
Share on other sites



According the helpfile the _FTP_FindFileFirst() returns 0 in case no next file is found.

So what do you think will happen on any reference to $aFile[?] in that case? ;)


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

According the helpfile the _FTP_FindFileFirst() returns 0 in case no next file is found.

So what do you think will happen on any reference to $aFile[?] in that case? ;)

If I understand correctly it will cause the error I have. I know It does go throught all 13 files in my ftp directory. I just don't know what the best solution would be to check a folder on an ftp site and compare a local folder and update files that are different on the local side.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

If I understand correctly it will cause the error I have. I know It does go throught all 13 files in my ftp directory. I just don't know what the best solution would be to check a folder on an ftp site and compare a local folder and update files that are different on the local side.

Your problem is that Do\Until loop tries to use $aFile before error checking. A normal error occurs when there are no more matching files. Try this structure instead:
While 1
    $aFile = _FTP_FindFileNext($h_Handle)
    If @error Then ExitLoop ; Normal exit when there are no more files
    
    ; ...
    
WEnd

;)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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