Jump to content

_FTP_FileRead problem


Recommended Posts

Hy all! Sorry of my bad english, but I have a problem.

This part of code must read the file on FTP (that was previous connected) and return what chars are in the file

$CHR = '/,^'

all is going good but when I press sumbit button ($SUMBIT) again, it return the same that the first time (even if needed file was changed)

please help me with this=)))

Case $SUMBIT
        GUICtrlSetData($STATUS, 'Stand by...')
        GUICtrlSetColor($STATUS, 0x0000FF)
        $CHR = GUICtrlRead($CHR)
        $FILE = GUICtrlRead($FILE)
        $FILEOPEN = _FTP_FileOpen($hConnect, $FILE)
        $FILEREAD = _FTP_FileRead($FILEOPEN, 100000)
        $STR = BinaryToString($FILEREAD)
        $a = StringSplit($CHR, ',')
        For $i = 1 To $a[0]
            If StringInStr($STR, $a[$i]) Then $LOG &= $a[$i] & ' found!' & @CRLF
        Next    
        GUICtrlSetData($STATUS, 'Connected')
        GUICtrlSetColor($STATUS, 0x00FF00)
        TrayTip('', $LOG, 30)
        _FTP_FileClose($FILEOPEN)
Link to comment
Share on other sites

Not seeing much, but I observe you don't check error condition anywhere. Could be simply that the second open doesn't work for some reason and $str gets self-identical.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

you don't check error condition anywhere

You were right! when I set error after reading file error has been occured...

but I dont understand why... :(

$FILEOPEN = _FTP_FileOpen($hConnect, $FILE)
        $FILEREAD = _FTP_FileRead($FILEOPEN, 100000)
        If @error Then MsgBox(16, 'error', 'error reading file')
Link to comment
Share on other sites

Perhaps because the _FTP_FileOpen fails? Error checking really should be done after every call where an error can possibly occur. FTP is blatantly error-prone, much more than GUI_CreateLabel. So while error-checking the latter is reasonably optional, doing sameafter the former is essentially obligatory.

Thanks for pointing out this truth with your example :(

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

this script is very important to me so I'm getting up this topic :(

I just want to remind you to be careful with that. Our rule on bumping is to wait 24 hours, ignore it too often and you will find yourself very unpopular. :)
Link to comment
Share on other sites

Maybe I dont understand correctly expressions in your last post( so this is my code, can you correct it a little and point on my mistakes?

thanks for your help)

#include <FTPEx.au3>
#include <GUIConstants.au3>

Global $PROGNAME = 'MyFTP Control'
Global $S = 0
Global $LOG

HotKeySet('{ESC}', 'Close')

$GUI = GUICreate($PROGNAME, 300, 230)
GUICtrlCreateGroup('', 5, 0, 290, 225)
GUICtrlCreateLabel('Server name\IP:', 15, 18)
$SERVER = GUICtrlCreateInput('', 150, 15, 120, 20)
GUICtrlCreateLabel('Username:', 15, 48)
$NAME = GUICtrlCreateInput('', 150, 45, 120, 20)
GUICtrlCreateLabel('Password:', 15, 78)
$PASS = GUICtrlCreateInput('', 150, 75, 120, 20)
GUICtrlCreateLabel('File to search:', 15, 108)
$FILE = GUICtrlCreateInput('1.txt', 150, 105, 120, 20)
$CONECT = GUICtrlCreateButton('Connect', 20, 190, 80, 30)
$DISCONECT = GUICtrlCreateButton('Disconnect', 105, 190, 90, 30)
GUICtrlSetState(-1, $GUI_DISABLE)
$SUMBIT = GUICtrlCreateButton('Read', 200, 190, 80, 30)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateLabel('What to search (through ","):', 15, 140)
$CHR = GUICtrlCreateInput('/,^', 150, 135, 120, 20)
GUICtrlCreateLabel('Status:', 15, 168)
$STATUS = GUICtrlCreateLabel('Disconnect', 150, 168)
GUICtrlSetColor(-1, 0xff0000)

GUISetState()

While 1 
    Switch GUIGetMsg()
    Case -3
        If $S = 1 Then _FTP_Close($FTP)
        Exit
    Case $CONECT
        $SERVER = GUICtrlRead($SERVER)
        $NAME = GUICtrlRead($NAME)
        $PASS = GUICtrlRead($PASS)
         Sleep(100)
         GUICtrlSetData($STATUS, 'Stand by...')
         GUICtrlSetColor($STATUS, 0x0000FF)
        $FTP = _FTP_Open('MyFTP Control')
        $hConnect = _FTP_Connect($FTP, $SERVER, $NAME, $PASS)
        If @error Then
            GUICtrlSetData($STATUS, 'Disconnect')
            GUICtrlSetColor($STATUS, 0xff0000)
            MsgBox(16, 'Error', 'Connection error!')
        Else
            $S = 1
            GUICtrlSetState($CONECT, $GUI_DISABLE)
            GUICtrlSetState($DISCONECT, $GUI_ENABLE)
            GUICtrlSetState($SUMBIT, $GUI_ENABLE)
            GUICtrlSetColor($STATUS, 0x00FF00)
            GUICtrlSetData($STATUS, 'Connect')
        EndIf
    Case $SUMBIT
        GUICtrlSetData($STATUS, 'Stand by...')
        GUICtrlSetColor($STATUS, 0x0000FF)
        $CHR = GUICtrlRead($CHR)
        $FILE = GUICtrlRead($FILE)
        $FILEOPEN = _FTP_FileOpen($hConnect, $FILE)
        $FILEREAD = _FTP_FileRead($FILEOPEN, 100000)
        If @error Then
            MsgBox(16, 'Error', 'Error reading file!')
            Exit
        EndIf
        $STR = BinaryToString($FILEREAD)
        $a = StringSplit($CHR, ',')
        For $i = 1 To $a[0]
            If StringInStr($STR, $a[$i]) Then $LOG &= $a[$i] & ' found!' & @CRLF
        Next    
        GUICtrlSetData($STATUS, 'Connect')
        GUICtrlSetColor($STATUS, 0x00FF00)
        TrayTip('', $LOG, 30)
        _FTP_FileClose($FILEOPEN)
    Case $DISCONECT
        GUICtrlSetData($STATUS, 'Stand by...')
        GUICtrlSetColor($STATUS, 0x0000FF)
        _FTP_Close($FTP)
        GUICtrlSetData($STATUS, 'Disconnect')
        GUICtrlSetColor($STATUS, 0xff0000)
        GUICtrlSetState($CONECT, $GUI_ENABLE)
        GUICtrlSetState($DISCONECT, $GUI_DISABLE)
        GUICtrlSetState($SUMBIT, $GUI_DISABLE)
        $S = 0
    EndSwitch
WEnd

Func Close()
    Exit
EndFunc
Link to comment
Share on other sites

That can't hurt and possibly catch error(s) occuring there.

$FILE = GUICtrlRead($FILE)

$FILEOPEN = _FTP_FileOpen($hConnect, $FILE)

If @error Then

MsgBox(16, 'Error', 'Error opening file!')

Exit

EndIf

$FILEREAD = _FTP_FileRead($FILEOPEN, 100000)

If @error Then

MsgBox(16, 'Error', 'Error reading file!')

Exit

EndIf

Posting will destroy formatting but you get the idea.

Sorry for hyper-elliptic english, I'm not native.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Can you FTP-read the file giving error with a known-working product (browser, Filezilla, ...)?

What is the @error returned by _FTP_FileRead and the returned size? What is the actual file size?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

1) I just mean: can you check that it's possible to ftp-read the file using temporarily another product known to work. Then you'll see if there is some extra problem (access right or something).

2) ConsoleWrite("@error = " & @error & @LF) <-- insert right after _FTP_FileRead(...) or else @error will get overwritten by another function.

3) the return value of _FTP_FileRead(...) is the number of byte successfully downloaded.

4) check that something else (like anti-virus program) isn't blocking the download by detecting false or true positive on this particular file.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

1.access rights is allright because I did that ok

2.@error = 0 ;first read

@error = 2 ;second read

3. I insert this 'MsgBox(0, '', $FILEREAD)' and $FILEREAD = 0

4.anti-virus is allright too

Link to comment
Share on other sites

An error value of 2 doesn't seem to mean anything. I spent much time on MSDN o no avail.

Honest, I've no idea what happens. Normally, all FTP download forces reload even if the file is on cache (that's because the file could have changed in the meantime on the server). So it should work, but...

Is that a FTP server or HTTP or something else? If FTP, you could try _FTP_FileGet. Maybe that would work better

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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...