Jump to content

Read Text File On Website


Recommended Posts

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!

Link to comment
Share on other sites

  • Moderators

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

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

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.

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

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

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.

Link to comment
Share on other sites

  • Moderators

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

Read my edit:

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

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

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.

Link to comment
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...

Link to comment
Share on other sites

  • Moderators

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

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.

Link to comment
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.
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...