Mini-FTP-Tool "fastData v0.13" - für die Community, vielleicht kann es jemand gebrauchen.

  • Hallo Community :) ,

    da mir hier bereits zahlreiche User geholfen haben und ich sehr begeistert über die Informationsflut bin, die auf diesem Board auch aktiv verteilt und weiterhin angetrieben wird, möchte ich mich mit einem kleinem Tool bedanken. Für den Einen oder Anderen ist es sicherlich hilfreich für andere / eigene Projekte oder es kann direkt so verwendet werden.

    * Kleine Hinweise was das Tool kann:
    * Upload, Download, Delete von Dateien in einem bestimmten Verzeichnis auf einem FTP-Server
    * Es ist noch ausbaufähig, doch als Überblick zu diesem Thema sicherlich gar nicht schlecht.

    Der Quellcode ist beliebig veränderbar und es muss keine Namensnennung oder so (siehe CC) stattfinden. Einfach ~have fun, I hope it will be helpful~ ;) .

    Spoiler anzeigen
    [autoit]


    ; ******************************************************************************
    ; **::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::**
    ; **::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::**
    ; **::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::**
    ; ** __ _ _____ _ **
    ; ** / _| | | | __ \ | | **
    ; ** | |_ __ _ ___| |_| | | | __ _| |_ __ _ **
    ; ** | _/ _` / __| __| | | |/ _` | __/ _` | **
    ; ** | || (_| \__ \ |_| |__| | (_| | || (_| | **
    ; ** |_| \__,_|___/\__|_____/ \__,_|\__\__,_| **
    ; ** **
    ; **::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::**
    ; **::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::**
    ; **::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::**
    ; ******************************************************************************

    [/autoit] [autoit][/autoit] [autoit]

    #region includes
    #include <Array.au3>
    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <File.au3>
    #include <FTPEx.au3>
    #include <GUIConstantsEx.au3>
    #include <GuiImageList.au3>
    #include <GuiListView.au3>
    #include <String.au3>
    #include <TreeViewConstants.au3>
    #include <WindowsConstants.au3>
    #endregion includes

    [/autoit] [autoit][/autoit] [autoit]

    #region GUI
    $oMain = GUICreate( "fastData v0.13", 322, 303, Default, Default, -1, BitOR( $WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE ) )
    $iListView = GUICtrlCreateListView( "", 8, 8, 305, 200 )
    $sFile = GUICtrlCreateInput( "", 8, 216, 305, 21 )
    GUICtrlSetState( -1, $GUI_DROPACCEPTED )
    $iBtn1 = GUICtrlCreateButton( "Upload!", 8, 245, 147, 21 )
    $iBtn2 = GUICtrlCreateButton( "Download!", 166, 245, 147, 21 )
    $iBtn3 = GUICtrlCreateButton( "Delete!", 8, 274, 305, 21 )
    GUISetState(@SW_SHOW)
    #endregion GUI

    [/autoit] [autoit][/autoit] [autoit]

    #region declaration
    $sRemote = "/html/verzeichnisebene1/verzeichnisebene2/fastData/" ; the specific directory for upload, download, delete
    $sLocal = @DesktopDir & "" ; the directory for the downloaded files
    $sServer = "website.com" ; e.g. website.com (have to be edited)
    $sUsername = "username" ; e.g. username (have to be edited)
    $sPass = "pwd" ; e.g. pwd (have to be edited)
    #endregion declaration

    [/autoit] [autoit][/autoit] [autoit]

    #region init
    Func _init()
    ; open a FTP-Session
    Global $hForCon = _FTP_Open( "FTP" )
    If $hForCon = 0 Then
    MsgBox( 16, "Error", "FTP-Session konnte nicht geöffnet werden." )
    Exit
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; open a FTP-Connection
    Global $con = _FTP_Connect( $hForCon, $sServer, $sUsername, $sPass, 1 )
    If $con = 0 Then
    MsgBox( 16, "Error", "Es konnte keine Verbindung aufgebaut werden." )
    _FTP_Close( $hForCon )
    Exit
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; set the specific path on the FTP-Environment
    $iSetPath = _FTP_DirSetCurrent( $con, $sRemote )
    If $iSetPath = 0 Then
    MsgBox( 16, "Error", "Es konnte nicht zum Verzeichnis ""fastData"" navigiert werden." )
    _FTP_Close( $hForCon )
    Exit
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; reset the ListView content
    _GUICtrlListView_DeleteColumn( $iListView, 0 )
    _GUICtrlListView_DeleteAllItems( GUICtrlGetHandle( $iListView ) )

    [/autoit] [autoit][/autoit] [autoit]

    ; create a file list of the specific path
    $aList = _FTP_ListToArray( $con, 2, $INTERNET_FLAG_RELOAD ) ; don't remove the flag (reload)

    [/autoit] [autoit][/autoit] [autoit]

    ; fill the ListView with the array (with the file list)
    _GUICtrlListView_AddColumn( $iListView, "Dateien zum Download", 301 )
    $iCount = $aList[0]
    If $aList[0] <> 0 Then
    Do
    _GUICtrlListView_AddItem( $iListView, $aList[$iCount] )
    $iCount = $iCount - 1
    Until $iCount = 0
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ; call this function
    _init()
    #endregion init

    [/autoit] [autoit][/autoit] [autoit]

    #region events
    While 1
    $eMsg = GUIGetMsg()
    Switch $eMsg
    Case $GUI_EVENT_CLOSE
    If MsgBox( 262144 + 308, "Hinweis", "Soll das Programm tatsächlich geschlossen werden?" ) = 6 Then
    _FTP_Close( $hForCon )
    Exit
    EndIf
    Case $iBtn1
    _ftpUpload()
    Case $iBtn2
    _ftpDownload()
    Case $iBtn3
    _ftpDelete()
    EndSwitch
    WEnd
    #endregion events

    [/autoit] [autoit][/autoit] [autoit]

    #region functions
    Func _ftpUpload()
    If GUICtrlRead( $sFile ) = "" Then
    MsgBox( 48, "Hinweis", "Es wurde nichts in die Inputbox eingegeben bzw. keine Datei wurde hineingezogen." )
    Return
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; get just the file without the path
    $sReverseFile = _StringReverse( GUICtrlRead( $sFile ) )
    $aFilename = _StringBetween( $sReverseFile, "", "" )
    $sFilename1 = _StringReverse( $aFilename[0] )
    $sOnServer = $sRemote & $sFilename1

    [/autoit] [autoit][/autoit] [autoit]

    ; upload
    $iUpload = _FTP_FilePut( $con, GUICtrlRead( $sFile ), $sOnServer )
    If $iUpload = 0 Then
    MsgBox( 16, "Error", "Fehler beim Upload!" )
    _FTP_Close( $hForCon )
    Exit
    EndIf
    MsgBox( 64, "Information", "Datei """ & $sFilename1 & """ ist erfolgreich hochgeladen." )

    [/autoit] [autoit][/autoit] [autoit]

    ; reset and renew
    GUICtrlSetData( $sFile, "" )
    _init()
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ftpDownload()
    ; download just the selected one
    $aSelectedItem = _GUICtrlListView_GetSelectedIndices( $iListView, True )
    If $aSelectedItem[0] <> 0 Then
    $sFilename2 = _GUICtrlListView_GetItemTextString( $iListView, $aSelectedItem[1] )
    $sFilename2 = StringReplace( $sFilename2, "|", "" )

    [/autoit] [autoit][/autoit] [autoit]

    ; download
    $iDownload = _FTP_FileGet( $con, $sRemote & $sFilename2, $sLocal & $sFilename2, False, 0, $INTERNET_FLAG_RELOAD )
    If $iDownload = 0 Then
    MsgBox( 16, "Error", "Fehler beim Download!" )
    Return
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    MsgBox( 64, "Information", "Datei """ & $sFilename2 & """ ist erfolgreich heruntergeladen (siehe Desktop)." )
    Else
    MsgBox( 48, "Hinweis", "Es wurde nichts zum Download ausgewählt." )
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ftpDelete()
    ; delete just the selected one
    $aSelectedItem = _GUICtrlListView_GetSelectedIndices( $iListView, True )
    If $aSelectedItem[0] <> 0 Then
    $sFilename2 = _GUICtrlListView_GetItemTextString( $iListView, $aSelectedItem[1] )
    $sFilename2 = StringReplace( $sFilename2, "|", "" )

    [/autoit] [autoit][/autoit] [autoit]

    ; delete
    $iDel = _FTP_FileDelete( $con, $sRemote & $sFilename2 )
    If $iDel = 0 Then
    MsgBox( 16, "Error", "Fehler beim Löschen!" )
    Return
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    MsgBox( 64, "Information", "Datei """ & $sFilename2 & """ ist erfolgreich gelöscht" )
    Else
    MsgBox( 48, "Hinweis", "Es wurde nichts zum Löschen ausgewählt." )
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; reset and renew
    _init()
    EndFunc
    #endregion functions

    [/autoit] [autoit][/autoit] [autoit]

    ; ----------------------------------- EOF --------------------------------------

    [/autoit] [autoit][/autoit] [autoit][/autoit]


    Bis auf die Region "declaration" sollte nichts angepasst werden müssen. Falls Fragen auftreten sollten, dann bitte immer her damit, doch die GUI ist so simple aufgebaut, dass es selbsterklärend sein sollte. Ich habe die meisten exceptions abgefangen bzw. melde entsprechend, trotzdem habe ich beim Test nicht alle Konstellationen geprüft.

    Das war's, UserIsGrateful

    ACHTUNG!!! In Zeile 44 und 125 fehlt der BACKSLASH - bei 44 sollte "\", bei 125 sollte "", "\" stehen!!! Im Anhang steht die korrigierte "*.au3"-Datei als download bereit ;) .

  • Hallo,

    dies habe ich bereits mehrfach versucht! Der BACKSLASH ist im Quellcode vorhanden, doch er wird nur in der Vorschau (beim Editieren) angezeigt. Auch wenn ich ihn mit Escape-Zeichen (u. a. auch "\") maskiere, passiert nix. Wieso ist das hier so? Kenne dieses Verhalten nur bei SQL-Injection-Abwähr bzw. XSS-Abwähr.

    Nutze den "Autoit-Quellcode" tag zur Anzeige des Skriptes.
    Irgendjemand dazu eine Idee?