Jump to content
akira2891

FTP get data in GUI list

Recommended Posts

Hi, i have problem to get all files from server in list, it say in help file that u can get data from current session but it wont work

 

#RequireAdmin
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIListBox.au3>
#include <GUIListView.au3>
#include <FTPEx.au3>
#include <Array.au3>

#Region ### START Koda GUI section ###
$GUI = GUICreate("FTP tool", 754, 613, 691, 157)
GUICtrlCreateLabel("Host", 16, 16, 26, 17)
GUICtrlCreateLabel("Port", 192, 16, 23, 17)
GUICtrlCreateLabel("Username", 16, 56, 52, 17)
GUICtrlCreateLabel("Password", 16, 88, 50, 17)
GUICtrlCreateLabel("Status : ", 8, 152, 43, 17)
$status = GUICtrlCreateLabel("Not connected", 52, 152, 221, 17)
$host = GUICtrlCreateInput("", 48, 12, 121, 21)
$port = GUICtrlCreateCombo("", 224, 12, 65, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "21|80")
$username = GUICtrlCreateInput("", 79, 52, 121, 21)
$password = GUICtrlCreateInput("", 79, 81, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
$connectBtn = GUICtrlCreateButton("CONNECT", 56, 192, 75, 25)
$disconnectBtn = GUICtrlCreateButton("DISCONNECT", 143, 192, 107, 25)
$List = GUICtrlCreateList("", 16, 240, 721, 340, 0)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

If GUICtrlRead($status) = 'Not connected' Then GUICtrlSetState($disconnectBtn, $GUI_DISABLE) ; disable disconnect button if not connected
GUICtrlSetData($port, '21') ; default port

Global $status, $host, $port, $username, $password, $FTPopen, $FTPConnect, $List

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $connectBtn
            _connectFTP()
        Case $disconnectBtn
            _disconnectFTP()

    EndSwitch
WEnd

; connection to FTP server
Func _connectFTP()

    Local $_host = GUICtrlRead($host) ; host name
    Local $_username = GUICtrlRead($username) ; username
    Local $_password = GUICtrlRead($password) ; password
    Local $_port = GUICtrlRead($port) ; port

    Local $FTPopen = _FTP_Open('FTP connection test') ; name of connection
    Local $FTPConnect = _FTP_Connect($FTPopen, $_host, $_username, $_password, '', $_port) ; connect

        ; try to connect to server
        If Not @error Then ; if not error
            GUICtrlSetData($status, 'Connected') ; set status to connected
            GUICtrlSetState($connectBtn, $GUI_DISABLE) ; disable connect button
            GUICtrlSetState($disconnectBtn, $GUI_ENABLE) ; enable disconnect button
            _listData()
        Else
            MsgBox(48, 'FTP connection error', "Can't connect to server, error = " & @error) ; if there is connection error
        EndIf

EndFunc

; disconnect from FTP server
Func _disconnectFTP()
    
    _FTP_Close($FTPopen)
    _FTP_Close($FTPConnect)
    GUICtrlSetState($disconnectBtn, $GUI_DISABLE)
    GUICtrlSetState($connectBtn, $GUI_ENABLE)
    GUICtrlSetData($status, 'Not connected')
    _GUICtrlListBox_ResetContent($List)
    
EndFunc

; list all files on FTP server
Func _listData()

    ; get current dir on server
    $FTPdirData = _FTP_DirGetCurrent($FTPopen)

    ; Add files in list box
    _GUICtrlListBox_BeginUpdate($List)
    _GUICtrlListBox_ResetContent($List)
    _GUICtrlListBox_Dir($List, "", $FTPdirData, False)
    _GUICtrlListBox_EndUpdate($List)


EndFunc

 

Edited by akira2891

Share this post


Link to post
Share on other sites

akira2891,

1 - Where is it failing?

2 - What is the value of $FTPdirData

3 - See _FTP_ListToArray in Help file.  You are not getting a list of files, just a directory name.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
#RequireAdmin
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIListBox.au3>
#include <GUIListView.au3>
#include <FTPEx.au3>
#include <Array.au3>

#Region ### START Koda GUI section ###
$GUI = GUICreate("FTP tool", 754, 613, 691, 157)
GUICtrlCreateLabel("Host", 16, 16, 26, 17)
GUICtrlCreateLabel("Port", 192, 16, 23, 17)
GUICtrlCreateLabel("Username", 16, 56, 52, 17)
GUICtrlCreateLabel("Password", 16, 88, 50, 17)
GUICtrlCreateLabel("Status : ", 8, 152, 43, 17)
$status = GUICtrlCreateLabel("Not connected", 52, 152, 221, 17)
$host = GUICtrlCreateInput("", 48, 12, 121, 21)
$port = GUICtrlCreateCombo("", 224, 12, 65, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "21|80")
$username = GUICtrlCreateInput("", 79, 52, 121, 21)
$password = GUICtrlCreateInput("", 79, 81, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
$connectBtn = GUICtrlCreateButton("CONNECT", 56, 192, 75, 25)
$disconnectBtn = GUICtrlCreateButton("DISCONNECT", 143, 192, 107, 25)
$List = GUICtrlCreateList("", 16, 240, 721, 340, 0)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

If GUICtrlRead($status) = 'Not connected' Then GUICtrlSetState($disconnectBtn, $GUI_DISABLE) ; disable disconnect button if not connected
GUICtrlSetData($port, '21') ; default port

Global $status, $host, $port, $username, $password, $FTPopen, $FTPConnect, $List

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $connectBtn
            _connectFTP()
        Case $disconnectBtn
            _disconnectFTP()

    EndSwitch
WEnd

; connection to FTP server
Func _connectFTP()

    Local $_host = GUICtrlRead($host) ; host name
    Local $_username = GUICtrlRead($username) ; username
    Local $_password = GUICtrlRead($password) ; password
    Local $_port = GUICtrlRead($port) ; port

    $FTPopen = _FTP_Open('FTP connection test',0) ; name of connection
    $FTPConnect = _FTP_Connect($FTPopen, $_host, $_username, $_password, '', $_port) ; connect

        ; try to connect to server
        If Not @error Then ; if not error
            GUICtrlSetData($status, 'Connected') ; set status to connected
            GUICtrlSetState($connectBtn, $GUI_DISABLE) ; disable connect button
            GUICtrlSetState($disconnectBtn, $GUI_ENABLE) ; enable disconnect button
            _listData()
        Else
            MsgBox(48, 'FTP connection error', "Can't connect to server, @error = " & @error & ", @extended = " & @extended) ; if there is connection error
        EndIf

EndFunc

; disconnect from FTP server
Func _disconnectFTP()

    _FTP_Close($FTPopen)
    _FTP_Close($FTPConnect)
    GUICtrlSetState($disconnectBtn, $GUI_DISABLE)
    GUICtrlSetState($connectBtn, $GUI_ENABLE)
    GUICtrlSetData($status, 'Not connected')
    _GUICtrlListBox_ResetContent($List)

EndFunc

; list all files on FTP server
Func _listData()

    ; get current dir on server
    $FTPdirData = _FTP_DirGetCurrent($FTPConnect)

;~  MsgBox(0, "", $FTPdirData & ', @error = ' & @error & ' , @extended = ' & @extended)

    ; Add files in list box
    _GUICtrlListBox_BeginUpdate($List)
    _GUICtrlListBox_ResetContent($List)
    _GUICtrlListBox_Dir($List, "", $FTPdirData, False)
    _GUICtrlListBox_EndUpdate($List)

EndFunc

 

Here is the updated script but now when i connect im getting list of my drives on computer ?


yVTsdMU.png

Share this post


Link to post
Share on other sites

akira,

Probably because of this

_GUICtrlListBox_Dir($List, "", $FTPdirData, False)

There is nothing in your code that gets a list of remote files, again, see _FTP_ListToArray in Help file.


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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

  • Similar Content

    • By nacerbaaziz
      good morning all.
      first lit me give you all a thinks to your help
      you're help me allot thank you all.
      sirs today i've a new problem
      it's not a problem but thing i want to add it to blind accessability.
      the ListBox can send a notification when the user send a double click on it items
      but as we know that the blind users can't use the mouse for that they use the keybord to navigate.
      as we know that the enter replace the double click on the keybord
      for that i need when the user send a inter above any listBox item the list send a double click notification.
      i know some of you tell me that i can use the  GUISetAccelerators function
      but the enter has a other tasks such as leav a blanc line on edits and activate the defaultButton and other tasks.
      that what i need and i hope that you can help me
      this is a simple example.
      #include <GUIConstantsEx.au3> #include <StructureConstants.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <ListBoxConstants.au3> Example() Func Example() Local $sMESSAGE = "The following buttons have been clicked" GUICreate("My GUI list") ; will create a dialog box that when displayed is centered Local $idButton_Add = GUICtrlCreateButton("Add", 64, 32, 75, 25) Local $idButton_Clear = GUICtrlCreateButton("Clear", 64, 72, 75, 25) global $idMylist = GUICtrlCreateList("buttons that have been clicked", 176, 32, 121, 97) GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling GUICtrlSetData(-1, $sMESSAGE) global $DummyList = GUICtrlCreateDummy() GUICtrlSendToDummy($DummyList, 1) Local $idButton_Close = GUICtrlCreateButton("my closing button", 64, 160, 175, 25) GUIRegisterMsg($WM_command, "WM_command") GUISetState(@SW_SHOW) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton_Add GUICtrlSetData($idMylist, "You clicked button No1|") Case $idButton_Clear GUICtrlSetData($idMylist, "") Case $idButton_Close MsgBox($MB_SYSTEMMODAL, "", "the closing button has been clicked", 2) Exit case $DummyList $g_iTemp = GUICtrlRead($DummyList) if $g_iTemp = $LBN_DBLCLK then ;$LBN_DBLCLK then msgBox(64, "", "") endIf GUICtrlSendToDummy($DummyList, 0) EndSwitch WEnd EndFunc ;==>Example Func WM_command($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = $lParam $iCode = BitShift($wParam, 16) ; Hi Word Switch $hWndFrom Case GUICtrlGetHandle($idMylist) Switch $iCode Case $LBN_SELCHANGE, $LBN_DBLCLK, $LBN_SELCANCEL, $LBN_SETFOCUS GUICtrlSendToDummy($DummyList, $iCode) case else ;GUICtrlSendToDummy($DummyTreeview, 1) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc  
    • By Dent
      The following function successfully connects to and uploads a local text file named user.dat
      I have checked the data being written to the text file when it is created locally using a MsgBox and it appears exactly how it should be written to the file. If I comment out the FileDelete and go and open the file locally it is as expected.
      However when I download the file from the FTP server and open it up the text that should be at the end of the file is missing. With each subsequent run more characters are missing.
      I added the Sleep(5000) in case the function was closing the FTP connection too quickly before the file could be fully written but it makes no difference. The user.dat file is (should be) approximately 100 bytes so it is tiny.
      Any idea why this is happening?
      Func UpdateUserData() ; Upload the modified user.dat file Local $hOpen = _FTP_Open("myftp") Local $hConn = _FTP_Connect($hOpen, "my.ftp.server", "user", "pass", 1, 0, 1, 2) If @error Then MsgBox(16, "Error", "Connection failed" & @CRLF & @CRLF & "Please contact support") _FTP_Close($hConn) _FTP_Close($hOpen) Exit EndIf _FTP_FilePut($hConn, @TempDir & "\user.dat", "user.dat") ; Upload the new user.dat file Sleep(5000) If @error <> 0 Then MsgBox(16, "Error", "Couldn't transmit data" & @CRLF & @CRLF & "Please contact support") _FTP_Close($hConn) _FTP_Close($hOpen) Exit EndIf _FTP_Close($hConn) _FTP_Close($hOpen) FileDelete(@TempDir & "\user.dat") EndFunc  
    • By Raywando
      Hello,
      This is my first post. So I’ve worked on a script for a while and I’m planning to publish it but the problem is that it connects to an FTP server at some point, and as you probably know FTP credentials are easily captured by a MITM attack or Wireshark (not sure if Wireshark does). So I thought if i can detect data capturing in the user’s network the script would stop. Any idea?.
      If there’s another workaround I’m happy to hear it. 
    • By Carm01
      Hello,
      I am attempting to pull a list of the directory structure from a public FTP where no username or password is required i.e:
      ftp://ftp.adobe.com/pub/adobe/
      Now I have looked all over the place and have failed find anything to accomplish, and if I found some, and the documentation is rather bleak for example;
      it does show something I am looking for, but there is no ftp.au3, and the usage and examples of what i want to do seems to elude me on this and it may not even apply to what I am trying to accomplish?
      I want to avoid using things with Internet explorer , and I have done some google searches. However nothing seems to help
      the documentation surrounding : _FTP_DirGetCurrent  references _FTP_Connect , and then references _FTP_Open , and regardless what I try I cannot get it to pull a list of directorys of files as a list.
       
      Any help is appreciated
       
       
       
    • By Jemboy
      Hi,
      Ones(some times twice) a month I get an e-mail with zip file, which has price updates from a supplier.
      I have to upload the file to an FTP to get it processed.
      When uploading the file, it will get "timestamped" with the time and date at which time the file was uploaded.
      Normally this is fine, because I mostly upload the file the same day.
      Sometimes it may take 1 or 2 days before I can upload the file.
      For historical purpose, I would like to have the file timestamped with the original date.
      I have tried using:  _FTP_Command ( $hFTPSession, "MFCT YYYYMMDDHHMMSS path") 
      however this command does not work or change the timestamp as I expected.
      Does anyone now a way how I can change the timestamp of a FTP-file?
×
×
  • Create New...