Jump to content

Need some guidance: FTP/File Read's


 Share

Recommended Posts

So I've never used FTP really so I'm kind of new to that, let me start by explaning what I want this program to do.

Here is the GUI and the script below the explanation.

ifdilx.png

 

So this will be a "who is playing" tracker for a group of people to see who is on and who's playing what. What I want to be able to do is have people upload a game (Possibly a text document with the Game Name/Host Name) to an FTP server, and whenever someone clicks the "Refresh" button it will pull all the text documents on there and display the Game Name/Host name in the listbox on the left.

I've looked into FTP and have gotten that started but hit a few bumps.

  1. How do I split up the text documents and make them easily retrievable?
  2. How do I read the text document and input it into my listbox?

 

Here is my current script, just the basics.

(Added in function for saving the text document and the possible format to do it in.

Func _Announce()
    $GameName = GuiCtrlRead($InputGameName)
    $HostName = GuiCtrlRead($InputHostName)
    If FileExists($HostName & ".txt") Then
        FileDelete($HostName & ".txt")
    EndIf
    _FileCreate($HostName & ".txt")
    FileWrite($HostName & ".txt", $GameName)
EndFunc
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <FTPEx.au3>

Local $server = '***.*.*.*'
Local $username = 'Test'
Local $pass = 'pass''


Opt("GUIOnEventMode", 1)

Global $File[2000][2000], $FileRead[2000][2000]

$MainGUI = GuiCreate("Sniper Announcer", 450,500)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

    GuiCtrlCreateLabel("Game List", 90, 50, 200)
    GuiCtrlSetFont(-1,14)
    $GameList = GUICtrlCreateList("", 20, 80, 230, 350)
    GUICtrlSetColor(-1, 0xff0000)
    GUICtrlSetLimit(-1, 200)

    GuiCtrlCreateLabel("Enter Game Name", 275, 75, 200)
    GuiCtrlSetFont(-1,14)
    $InputGameName = GuiCtrlCreateInput("", 265, 100,170,30, $ES_Center)
    GUICtrlSetColor(-1, 0xff0000)
    GuiCtrlSetFont(-1,12)
    GuiCtrlCreateLabel("Enter Host Name", 280, 365, 200)
    GuiCtrlSetFont(-1, 14)
    $InputHostName = GuiCtrlCreateInput("", 265, 390, 170, 30, $ES_Center)
    GUICtrlSetColor(-1, 0xff0000)
    GuiCtrlSetFont(-1,12)

    $RefreshButton = GuiCtrlCreateButton("Refresh", 90,445, 100,30)
    GuiCtrlSetFont(-1,12)
    GUICtrlSetOnEvent(-1, "_Refresh")

    $AnnounceButton = GuiCtrlCreateButton("Announce", 260,445,100,30)
    GuiCtrlSetFont(-1,12)
        GUICtrlSetOnEvent(-1, "_Announce")
GuiSetState()

Func _Announce()
    $GameName = GuiCtrlRead($InputGameName)
    $HostName = GuiCtrlRead($InputHostName)
    If FileExists($HostName & ".txt") Then
        FileDelete($HostName & ".txt")
    EndIf
    _FileCreate($HostName & ".txt")
    FileWrite($HostName & ".txt", $GameName)
EndFunc

Func _Refresh()
    $Dir = FileChangeDir (@ScriptDir)
    Local $Open = _FTP_Open('MyFTP Control')
    Local $Conn = _FTP_Connect($Open, $server, $username, $pass)
    $File = _FTp_FileGet($Conn, "\GameInfo.txt", @WorkingDir & "\GameInfo.txt")
    Local $Ftpc = _FTP_Close($Open)
EndFunc


Func _Exit()
    Exit
EndFunc

While 1
    Sleep(10)
WEnd

Thanks in advance!

Edited by Damein

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Link to comment
Share on other sites

So, its a little dirty but I got it all to work!

In case anyone wants to use it as a reference I will post here.

Func _Announce()
Global $Open = _FTP_Open('MyFTP Control')
Global $Conn = _FTP_Connect($Open, $server, $username, $pass)
Global $DirOfServer = _FTP_DirSetCurrent($Conn, "GameInfo")
    Global $GameName = GuiCtrlRead($InputGameName)
    Global $HostName = GuiCtrlRead($InputHostName)
    Global $GameTime = GuiCtrlRead($InputTime)
    If FileExists($HostName & ".txt") Then
        FileDelete($HostName & ".txt")
    EndIf
    _FileCreate($HostName & ".txt")
    Local $openfile = FileOpen($HostName & ".txt", 1)
    FileWriteLine($HostName & ".txt", $HostName)
    FileWriteLine($HostName & ".txt", $GameName)
    FileWriteLine($HostName & ".txt", $GameTime)
    FileClose($openfile)
    $Dir = FileChangeDir (@ScriptDir)
    _Ftp_FilePut($Conn, $HostName & ".txt", "/GameInfo/" & $HostName & ".txt")
        Local $Ftpc = _FTP_Close($Open)
    _Refresh()
EndFunc

Func _Refresh()
    _GUICtrlTreeView_DeleteAll($GameTreeView)
Global $Open = _FTP_Open('MyFTP Control')
Global $Conn = _FTP_Connect($Open, $server, $username, $pass)
Global $DirOfServer = _FTP_DirSetCurrent($Conn, "GameInfo")
    $Dir = FileChangeDir (@ScriptDir)
    $Contents = _FTP_ListToArray($Conn, 2)
    For $i = 0 To UBound($Contents) - 1
    $File = _FTp_FileGet($Conn,  "/GameInfo/" & $Contents[$i], @WorkingDir & "/Games/" & $Contents[$i])
    Next
    Local $Ftpc = _FTP_Close($Open)

While UBound($GameListings)
    $Count += 1
    _ArrayPop($GameListings)
    _ArrayDelete($GameListings, $Count)
WEnd

Global $GameListings[2000]
Global $GameName[2000]
$Count = 0

    $Dir = FileChangeDir(@ScriptDir & "/Games")
    Local $search = FileFindFirstFile("*.*")

    While 1
        Local $file = FileFindNextFile($search)
    If @error Then ExitLoop
        $Count += 1
        $GameListings[$Count] = FileRead($file)
    WEnd
        FileClose($search)

    For $i = 1 To UBound($GameListings)
        $GameNumber += 1
        If $GameListings[$i] = "" Then
            ExitLoop
        EndIf
    Next
    For $i = 1 To $GameNumber - 1
        $StringSplit1 = StringSplit($GameListings[$i], @LF)
        $GameListData = $GameTreeView + $GameListings[$i]
        $GameNameItemHost = GUICtrlCreateTreeViewItem($StringSplit1[1], $GameTreeView)
        GUICtrlCreateTreeViewItem($StringSplit1[2], $GameNameItemHost)
        GUICtrlCreateTreeViewItem($StringSplit1[3], $GameNameItemHost)
    Next
    $Count = 0
    $GameNumber = 0
    $Refresh = 1
    Local $Ftpc = _FTP_Close($Open)
EndFunc

Incidentally, if anyone has a way to where I can keep the connection open without having to close/re-open that would be great. When attempting to do this the Treeview would not update due to it not refresing I suppose?

Edited by Damein

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

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