Jump to content

Compiled script works differently than .au3 file run from sciTE editor


Recommended Posts

Hi,

This is weird. I have a script that works perfectly when run from within the sciTE editor (using F5) but when it is compiled and run it doesn't operate correctly.

The script (main part added below) is designed to read information from an ini file and loop around a series of directories getting files from an FTP server. I have added several "msgbox" lines to the script to see what is happening. It seems that when the script is run from within sciTE editor when it actions the lines _FTP_FindFileFirst or FTP_FindFileNext in the first element of the array ($FileArray) it gets the number of files in the directory meeting the file specification. When run as an executable these lines always return a zero - suggesting there are no files.

Operating in both modes it gets the directory names from the ini file, hence my "msgbox" debug lines display exactly the correct directories to look at.

I have been using Autoit for many years now and have many of these FTP scripts working on remote PC's (20+) as well as several PC's at the office. The remote units send files to our FTP server, the office PCs retrieve the files from the FTP server putting them onto one of our servers. My own desktop machine gets files from our FTP server every few minutes and the code it uses is exactly the same except for the directories on the FTP server and on the archive server - these are governed by an appropriate ini file.

I would appreciate some thoughts on this if anyone else has encountered this problem.

George

This is the meat of my script

for $Dir=1 to $NumDirs
;read variables from ini file
    $OutDirectory=IniRead($IniFile,'Directory' & $Dir,'OutDirectory',"")
    $InDirectory=IniRead($IniFile,'Directory' & $Dir,'InDirectory',"")
    $FileWildCard=IniRead($IniFile,'Directory' & $Dir,'FileWildCard',"")

;a few debug line
msgBox(0,"NumDirs",$NumDirs)
msgBox(0,"LogFile",$LogFile)
msgBox(0,"OutDirectory",$OutDirectory)
msgBox(0,"InDirectory",$InDirectory)
;msgBox(0,"MoveDirectory",$MoveDirectory)
msgBox(0,"FileWildCard",$FileWildCard)
$FilesToFind=$InDirectory & $FileWildCard
msgbox(1,"FileToFind",$FilesToFind)
;go find Files

    $FileArray = _FTP_FindFileFirst($Conn,$FilesToFind,$FileHandle)
    msgbox(1,"NumFiles",$FileArray[0])
      If $FileArray[0] <> 0 then
         For $FileNum=1 to $FileArray[0]
            msgbox(1,"This File is ",$FileArray[10])
            $InFile=$InDirectory & $FileArray[10]        ;add file name to indirectory
            $OutFile=$OutDirectory & $FileArray[10]        ;add file name to outdirectory
            msgbox(0,"InFile",$InFile)
            msgbox(0,"OutFile",$OutFile)
            $Ftpp = _FTP_FileGet($Conn, $InFile, $OutFile )    ;go get file
            if $Ftpp=1 Then        ;$Ftpp is 1 if successful, therefore delete file
               FileWriteLine($Log,_Now() & " File copied from FTP Server  " & $InFile & "   to " & $OutFile)
               _FTP_FileDelete($Conn,$InFile)
            Else
               FilewriteLine($Log,_Now() & "   " & $InFile & " " & @error & @CRLF)    ;otherwise write error to log file
            EndIf

            $FileArray = _FTP_FindFileNext($FileHandle)        ;get next file
         Next
      Endif
      _FTP_FindFileClose($FileHandle)    ;clear find file handle ready for next use
Next

 

And here is the ini file

[Directories]
NumDirs=6

;Site1
[Directory1]
OutDirectory="R:\Hamilton\General-Archive\Cam-era\Full Archive\Tairua\LogFiles\"
InDirectory="/incoming/Cam-Era_LogFiles/Tairua/"
FileWildCard="*.log"

;Site2
[Directory2]
OutDirectory="R:\Hamilton\General-Archive\Cam-era\Full Archive\RaglanA\LogFiles\"
InDirectory="/incoming/Cam-Era_LogFiles/Raglan/"
FileWildCard="*.log"

;Site3
[Directory3]
OutDirectory="R:\Hamilton\General-Archive\Cam-era\Full Archive\PauanuiNorth\LogFiles\"
InDirectory="/incoming/Cam-Era_LogFiles/PauanuiNorth/"
FileWildCard="*.log"

;Site4
[Directory4]
OutDirectory="R:\Hamilton\General-Archive\Cam-era\Full Archive\PauanuiSouth\LogFiles\"
InDirectory="/incoming/Cam-Era_LogFiles/PauanuiSouth/"
FileWildCard="*.log"

;Site5
[Directory5]
OutDirectory="R:\Hamilton\General-Archive\Cam-era\Full Archive\PortOtagoA\LogFiles\"
InDirectory="/incoming/Cam-Era_LogFiles/PortOtagoA/"
FileWildCard="*.log"

;Site6
[Directory6]
OutDirectory="R:\Hamilton\General-Archive\Cam-era\Full Archive\PortOtagoB\LogFiles\"
InDirectory="/incoming/Cam-Era_LogFiles/PortOtagoB/"
FileWildCard="*.log"

 

Link to post
Share on other sites

Hey, fellow Kiwi :)  Unsure if its related but I had similar issue with InetGet, found that my script ran fine via Scite (downloading the latest Microsoft Teams clien), but failed when run off shared drive, found that I had to run the executable from a trusted path for example the desktop, otherwise it would fail to connect to the remote server and download the file.

Link to post
Share on other sites

I have had similar experiences. I believe it may be UAL or Windows Defender related. Specifically I have struggled to copy files over the network when the user is not logged on, probably related to permission levels. failed when run off shared drive 

Running activities in non-hidden windows solved some of my problems.

Edited by Skysnake

Skysnake

Why is the snake in the sky?

Link to post
Share on other sites

Hi All,

Thanks for your input.

JockoDundee - my script stops if it fails open and/or connect to the FTP server - it writes a message to the console, so it is opening and connecting - see code snippet below

Subz and Skysnake - the compiled script is running from my C drive, it is moving files from our FTP server to an archive server. It won't copy files via the executable even if I am active on the computer (so no problem with a user not being logged in etc.). I also have a script (executable) that picks up files from the same FTP server every 30 minutes, it is getting the files from an allied directory on the FTP server and putting them to an allied directory on the archive server - this works fine.

 

FTP open and Connect code - this does not produce any messages so the code is definitely opening a connection then connecting

$Open = _FTP_Open('MyFTP Control')
if $Open==0 then
    $Msg=_Now()&'   Unable to open FTP session'
    FileWrite($Log,$Msg)
EndIf
;msgbox(0,"Info","Ftp connection opened")
$Conn = _FTP_Connect($Open, $server, $username, $pass,0)
if $Conn==0 then
    $Msg=_Now()&'   Unable to connect FTP session'& @CRLF
    FileWrite($Log,$Msg)
Endif

Regards

George

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...