Jump to content

Recommended Posts

Posted

Hi,

I'm a new member or this forum and newbie in AutoIT.

My inspiration is to create a AutoIT script (FTPUploader06.au3), where the user can define what data should be uploaded (one or more files (jpg, bmp, png, avi, mpg) , an hole folder or a archive file (zip, rar).

Also the user should have the possibility to change the default FTP Server, FTP User and type in his own password.

The first basics of the script are working, but I get an error during compile.

Also a test file was not uploaded (as I have selected 'archives' to upload).

Can anyone help me to complete this script?

-> check the upload functionality (current error: 92,37 -> WARNING: $Open possibly not declared/created yet

-> verifying the part, where you can select the different kinds of files ...

Till now, I wrote only little and very easy scripts.

Maybe anyone can help me, thank's

Greetings,

chiller

FTPUploader06.au3

Posted

Hi chiller,

as you have:

Opt('MustDeclareVars', 1)

on top of your script, you'll need to declare all variables to initialize them. Simply $a = 1 + 1 is not enough.

Regards,

Hannes

:)

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Posted

Hallo chiller,

you must also respect the ftp-name convetions:

#cs ----------------------------------------------------------------------------
    AutoIt Version: 3.3.6.1
    Author:         chiller

    Script Function:
    FTP Upload tool
#ce ----------------------------------------------------------------------------
#include <FTP.au3>
#include <FTPEx.au3>
#include <Array.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>

$width = '500'
$height = '250'
$FileOrFolder = 'nd'
;MsgBox(4, "", $FileOrFolder) ;testeintrag
$server = InputBox("FTP Server", "Bitte den gewünschten FTP Server angeben (z.B. hillercn.homedns.org):", "10.50.21.108", "", $width, $height) ;Eingabe der FTP Server URL
If @error = '1' Then Exit
$ftpuser = InputBox("FTP Benutzernamen", "Geben Sie Ihren FTP Benutzernamen ein (z.B. chiller):", "Administrator", "", $width, $height) ; Eingabe des FTP Benutzers
If @error = '1' Then Exit
$ftppw = InputBox("FTP Passwort", "Bitte geben Sie Ihr FTP Passwort ein:", "", "*", $width, $height) ; Eingabe des FTP Passworts
If @error = '1' Then Exit
$message = "Ctrl oder Shift drücken um mehrere Dateien zu markieren"

;While $FileOrFolder Not "datei" Or $FileOrFolder Not "Datei" Or $FileOrFolder Not "verzeichnis" Or $FileOrFolder Not "Verzeichnis"
; $FileOrFolder = InputBox("Datei(en) oder Verzeichnis hochladen?", "Geben Sie das Wort 'Datei' bzw. 'Verzeichnis' ein:", "Datei", "", $width, $height)
; MsgBox(4, "", $FileOrFolder) ;testeintrag
;WEnd

Opt('MustDeclareVars', 1)
;Example()
;Func Example()
Local $button_1, $group_1, $radio_1, $radio_2, $radio_3
Local $radioval1, $radioval2, $msg
Local $auswahl, $message, $datei, $verzeichnis
Local $Open, $Conn, $ftpuser, $ftppw, $ftpFile

Opt("GUICoordMode", 1)
GUICreate("Was soll übertragen werden?", $width, $height)

; Create the controls
$button_1 = GUICtrlCreateButton("&Bestätigen", 30, 190, 120, 40)
$group_1 = GUICtrlCreateGroup("Auswahl:", 30, 20, $width - 60, $height - 100)
GUIStartGroup()
$radio_1 = GUICtrlCreateRadio("&Datei(en) (Bild01.jpg, Bild02.jpg, ...)", 50, 50, $width - 40, 20)
$radio_2 = GUICtrlCreateRadio("&Verzeichnis (C:\MeineBilder\)", 50, 80, $width - 40, 20)
$radio_3 = GUICtrlCreateRadio("&Archiv (*.zip, *.rar)", 50, 110, $width - 40, 20)


; Init our vars that we will use to keep track of GUI events
$radioval1 = 0 ; We will assume 0 = first radio button selected, 2 = last button
$radioval2 = 2


GUISetState() ;Zeigt die GUI


While $msg <> $button_1
    $msg = GUIGetMsg()
    Select
        Case $msg = $button_1
            $auswahl = $radioval1
        Case $msg >= $radio_1 And $msg <= $radio_3
            $radioval1 = $msg - $radio_1
    EndSelect
WEnd

Switch $auswahl
    Case 0
        $datei = FileOpenDialog($message, "C:\", "Images (*.jpg;*.bmp;*.png )|Videos (*.avi;*.mpg)", 1 + 4)
        If @error Then
            MsgBox(4096, "", "Fehler: Es wurde keine Auswahl getroffen!")
        Else
            $datei = StringReplace($datei, "|", @CRLF)
            MsgBox(4096, "", "Auswahl: " & $datei)
        EndIf
    Case 1
        $verzeichnis = FileSelectFolder("Verzeichnis auswählen", "")
        If @error Then
            MsgBox(4096, "", "Fehler: Es wurde keine Auswahl getroffen!")
        Else
            MsgBox(4096, "", "Auswahl: " & $verzeichnis)
        EndIf
    Case 2
        $datei = FileOpenDialog("Archiv auswählen", "C:\", "Archiv (*.zip;*rar)", 1)
        If @error Then
            MsgBox(4096, "", "Fehler: Es wurde keine Auswahl getroffen!")
        Else
            $datei = StringReplace($datei, "|", @CRLF)
            $ftpfile = StringSplit($datei,"\")
            if IsArray($ftpFile) Then $ftpfile= "/" & $ftpfile[$ftpFile[0]]
            ConsoleWrite($ftpFile & @CRLF);just for debugg is the correct for ftp-convetions?
            MsgBox(4096, "", "Auswahl: " & $datei)
            $Open = _FTPOpen("MyFTP_Control")
            If Not @error Then
                $Conn = _FTPConnect($Open, $server, $ftpuser, $ftppw)
                If Not @error Then
                    If _FtpPutFile($Conn, $datei, $ftpFile) Then
                        MsgBox(0, "Upload", "erfolgreich")
                        _FTPClose($Open)
                    Else
                        MsgBox(0, "Upload", "fehlgeschlagen")
                    EndIf
                Else
                    MsgBox(0, "Connect", "fehlgeschlagen")
                EndIf
            Else
                MsgBox(0, "OPen", "fehlgeschlagen")
            EndIf
        EndIf
EndSwitch

MsgBox(0, "$auswahl", $auswahl)
;EndFunc   ;==>Example
i hope it works, i couldn't test it

mfg autoBert

  • 2 weeks later...

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...