Sign in to follow this  
Followers 0
Jamie2312

Read Text File On Website

16 posts in this topic

Hey everyone, I am trying to write a program, in which can open a text file uploaded to a website. This is the coding I have so far:

$passcorrect = FileOpen("http://users.tpg.com.au/gmack60/password.txt", 0)

; Check if file opened for reading OK

If $passcorrect = -1 Then

MsgBox(0, "Error", "Unable to open password file. Please try again later.")

Exit

EndIf

While 1

$data = FileReadLine($passcorrect), 1))

If @error = -1 Then ExitLoop

WEnd

FileClose($passcorrect)

$password = String(InputBox("Control Centre","Please enter password to access this program:"))

If $password <> $data Then

MsgBox(4096,"Incorrect Password","Incorrect Password... Good bye!",0)

EXIT

Could anyone tell me what is wrong with my coding? Thanks!

Share this post


Link to post
Share on other sites



Hey everyone, I am trying to write a program, in which can open a text file uploaded to a website. This is the coding I have so far:

$passcorrect = FileOpen("http://users.tpg.com.au/gmack60/password.txt", 0)

; Check if file opened for reading OK

If $passcorrect = -1 Then

MsgBox(0, "Error", "Unable to open password file. Please try again later.")

Exit

EndIf

While 1

$data = FileReadLine($passcorrect), 1))

If @error = -1 Then ExitLoop

WEnd

FileClose($passcorrect)

$password = String(InputBox("Control Centre","Please enter password to access this program:"))

If $password <> $data Then

MsgBox(4096,"Incorrect Password","Incorrect Password... Good bye!",0)

EXIT

Could anyone tell me what is wrong with my coding? Thanks!

You have to download the .txt file first, take a look at InetGet() in the help file. (I can't remember if it's Beta or release)

If it's in Beta than download that here:

http://www.autoitscript.com/forum/index.php?showtopic=19717


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You have to download the .txt file first, take a look at InetGet() in the help file. (I can't remember if it's Beta or release)

If it's in Beta than download that here:

http://www.autoitscript.com/forum/index.php?showtopic=19717

Thanks, Ill try and code it now but if you could post what you would do (for this example), that would be great...

UPDATE: Its a password file so where should I download it to, so a novice user would not find it???

Edited by Jamie2312

Share this post


Link to post
Share on other sites

Thanks, Ill try and code it now but if you could post what you would do (for this example), that would be great...

UPDATE: Its a password file so where should I download it to, so a novice user would not find it???

Well if you looked at my desktop at the moment, I wouldn't find it there :), most people use @TempDir and then FileDelete() it once it's been read.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Well if you looked at my desktop at the moment, I wouldn't find it there :), most people use @TempDir and then FileDelete() it once it's been read.

lol... I put in your suggestion (inetget) but for some reason its not working - could you modify the below code so it will work with the TempDir and FileDelete() in it...

InetGet("http://users.tpg.com.au/gmack60/password.txt", "password.txt", 1, 1)

$passcorrect = FileOpen("password.txt", 0)

; Check if file opened for reading OK

If $passcorrect = -1 Then

MsgBox(0, "Error", "Unable to open password file. Please try again later.")

Exit

EndIf

While 1

$data = FileReadLine($passcorrect), 1)

If @error = -1 Then ExitLoop

WEnd

FileClose($passcorrect)

$password = String(InputBox("Control Centre","Please enter password to access this program:"))

If $password <> $data Then

MsgBox(4096,"Incorrect Password","Incorrect Password... Good bye!",0)

EXIT

Else

Thanks so much!

Edited by Jamie2312

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

InetGet("http://users.tpg.com.au/gmack60/password.txt", @TempDir & "\110~pass2203.txt")
$passcorrect = FileOpen(@TempDir & "\110~pass2203.txt", 0)
; Check if file opened for reading OK
If $passcorrect = -1 Then
MsgBox(0, "Error", "Unable to open password file. Please try again later.")
Exit
EndIf 

While 1
$data = FileReadLine($passcorrect), 1))
If @error = -1 Then ExitLoop
WEnd
FileClose($passcorrect)
FileDelete(@TempDir & "\110~pass2203.txt")

$password = String(InputBox("Control Centre","Please enter password to access this program:"))
If $password <> $data Then
MsgBox(4096,"Incorrect Password","Incorrect Password... Good bye!",0)
EXIT
EndIf

#)

Edit: Forgot the EndIf

Edited by nfwu

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Its coming up with an error on line 12 still - $data = FileReadLine($passcorrect), 1)). (The endif was at the end of the program which i didnt include as it is fairly lengthy)

Edited by Jamie2312

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Its coming up with an error on line 12 still - $data = FileReadLine($passcorrect), 1)). (The endif was at the end of the program which i didnt include as it is fairly lengthy)

Take off the extra ")" after FileReadLine and after $passcorrect on the same line:
InetGet("http://users.tpg.com.au/gmack60/password.txt", @TempDir & "\110~pass2203.txt")
$passcorrect = FileOpen(@TempDir & "\110~pass2203.txt", 0)
; Check if file opened for reading OK
If $passcorrect = -1 Then
    MsgBox(0, "Error", "Unable to open password file. Please try again later.")
    Exit
EndIf
While 1
    $data = FileReadLine($passcorrect, 1)
    If @error = -1 Then ExitLoop
WEnd
FileClose($passcorrect)
FileDelete(@TempDir & "\110~pass2203.txt")
$password = String(InputBox("Control Centre","Please enter password to access this program:"))
If $password <> $data Then
    MsgBox(4096,"Incorrect Password","Incorrect Password... Good bye!",0)
    Exit
EndIf
Edit:

Also when posting code, rather than using the "Bold" ust the [code ] [/code ] tags (without spaces), makes it easier to read.

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Its still coming up with the same error once i took off the extra ) - illegal text, one statement per line

Share this post


Link to post
Share on other sites

Its still coming up with the same error once i took off the extra ) - illegal text, one statement per line

Read my edit:

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Read my edit:

Thanks, somethings happening but the script is pausing for some reason - why is this? Is my firewall blocking the download or something? or is it the positioning of my endif (at the very end of program)

Edited by Jamie2312

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

You're stuck in the While 1 loop because you are only ever reading line 1 so it's never an error

InetGet("http://users.tpg.com.au/gmack60/password.txt", @TempDir & "\110~pass2203.txt")
$passcorrect = FileOpen(@TempDir & "\110~pass2203.txt", 0)
; Check if file opened for reading OK
If $passcorrect = -1 Then
    MsgBox(0, "Error", "Unable to open password file. Please try again later.")
    Exit
EndIf
$data = FileReadLine($passcorrect, 1)
If @error = - 1 Then Exit
FileClose($passcorrect)
FileDelete(@TempDir & "\110~pass2203.txt")
$password = String(InputBox("Control Centre","Please enter password to access this program:"))
If $password <> $data Then
    MsgBox(4096,"Incorrect Password","Incorrect Password... Good bye!",0)
    Exit
EndIf

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

You're stuck in the While 1 loop because you are only ever reading line 1 so it's never an error

InetGet("http://users.tpg.com.au/gmack60/password.txt", @TempDir & "\110~pass2203.txt")
$passcorrect = FileOpen(@TempDir & "\110~pass2203.txt", 0)
; Check if file opened for reading OK
If $passcorrect = -1 Then
    MsgBox(0, "Error", "Unable to open password file. Please try again later.")
    Exit
EndIf
$data = FileReadLine($passcorrect, 1)
If @error = - 1 Then Exit
FileClose($passcorrect)
FileDelete(@TempDir & "\110~pass2203.txt")
$password = String(InputBox("Control Centre","Please enter password to access this program:"))
If $password <> $data Then
    MsgBox(4096,"Incorrect Password","Incorrect Password... Good bye!",0)
    Exit
EndIf
Yey, its working! Thanks everyone for your help... Youve been great. Sorry guys but this is my first time at autoit

Thanks again...

Share this post


Link to post
Share on other sites

Yey, its working! Thanks everyone for your help... Youve been great. Sorry guys but this is my first time at autoit

Thanks again...

Good... you did pretty good for your first time out couple of issues, but easily fixable if you know the functions and what the errors are for, I might suggest trying out Valuaters AutoIt 123 to help speed things along for you if you haven't already.

http://www.autoitscript.com/forum/index.php?showtopic=21048


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Thanks, Ill have a look at it :)

Share this post


Link to post
Share on other sites

Hey everyone, I am trying to write a program, in which can open a text file uploaded to a website. This is the coding I have so far:

$passcorrect = FileOpen("http://users.tpg.com.au/gmack60/password.txt", 0)

; Check if file opened for reading OK

If $passcorrect = -1 Then

MsgBox(0, "Error", "Unable to open password file. Please try again later.")

Exit

EndIf

While 1

$data = FileReadLine($passcorrect), 1))

If @error = -1 Then ExitLoop

WEnd

FileClose($passcorrect)

$password = String(InputBox("Control Centre","Please enter password to access this program:"))

If $password <> $data Then

MsgBox(4096,"Incorrect Password","Incorrect Password... Good bye!",0)

EXIT

Could anyone tell me what is wrong with my coding? Thanks!

Um, now that the entire Internet knows where you store your password, you should change the location of the file and the contents of the current one, and all sites where you have used the current one.

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