1. Diese Seite verwendet Cookies. Wenn du dich weiterhin auf dieser Seite aufhältst, akzeptierst du unseren Einsatz von Cookies. Weitere Informationen

Upload von ausgewählten Dateien

Dieses Thema im Forum "AppleScript" wurde erstellt von plaetzchen, 07.01.07.

  1. plaetzchen

    plaetzchen Kaiserapfel

    Dabei seit:
    21.10.05
    Beiträge:
    1.729
    Hallo!

    Ich brauche da mal ein Script. Der soll folgendes machen:
    Schauen welche Dateien und Ordner im Finder ausgewählt sind und diese mit Cyberduck auf einen Server hochladen.

    Das ist bis jetzt dabei rausgekommen:

    set dateien to 0
    tell application "Finder"
    set dateien to result of (get selection)
    end tell
    tell application "Cyberduck"
    activate
    set the_browser to (make new browser)
    tell (the_browser)
    set encoding to "UTF-8"
    connect to "www.server.de" as user "user" with initial folder "upload"
    repeat with theFile in dateien
    upload item theFile
    end repeat
    end tell
    end tell

    Aber da kriege ich immer den falschen Dateien Typ. Wer kann helfen?

    Gruß

    Das schattige plaetzchen
     
  2. hubionmac

    hubionmac Rheinischer Krummstiel

    Dabei seit:
    25.06.04
    Beiträge:
    379
    Ich habe zwar nicht direkt Dein Script aufgegriffen, dafür aber einen schnellere Lösung gefunden, die ganz ohne Cyberduck auskommt.
    1. Es ist ein AppleScript (Dateien auf das Skript-Programm ziehen), dass Upload Links in einer verschüsselten Datei (inkl. Passwort) abspeichert
    2. Die verschlüsselte Bookmark-Datei beim Start öffnen (kennwort dazu ist im Schlüsselbund hinterlegt)
    3. Dich dann fragt, wohin du es laden möchtest
    4. und dann das ganze via CURL (im Terminal) hochlädt.
    Ich denke für größere Uploads nicht ganz so toll (kein Fortschrittsbalken), aber für kleine, häufige Uploads gar nicht mal so eine schlechte Lösung.

    Quellen (von denen ich geklaut habe =) ):und hier das Script (als Skript-Programm abspeichern!):
    Code:
    property myKeyName : "FTP-Upload-Script-PW"
    property keyDescription : "Administrator-Kennwort"
    property theAppName : "FTP-Upload-Script"
    property theAppVersion : "Rev. 2"
    on open these_items
        set theKey to getKey()
        tell application "Keychain Scripting" to set userpass to password of theKey
        --## bookmarks auslesen
        set pathtome to path to me
        tell application "Finder" to set myfolderx to (POSIX path of (container of (pathtome as alias) as alias))
        set newbookmarkfile to false
        try
            -- eine Liste bauen
            set bookmark_text to do shell script "cd " & quoted form of myfolderx & "; cat bookmarks.txt | openssl enc -d -aes-256-cbc -in bookmarks.txt -pass pass:" & userpass
            set AppleScript's text item delimiters to ASCII character 13
            set bookmark_list_all to every text item of bookmark_text
            set bookmark_list_at to {}
            set AppleScript's text item delimiters to "@"
            repeat with b in bookmark_list_all
                set bookmark_list_at to bookmark_list_at & text item 2 of b
            end repeat
            set AppleScript's text item delimiters to ""
            
            set bookmark_list_url to {"••Hinzufügen••", "••Löschen••"}
            repeat with i from 1 to (count of every item of bookmark_list_at)
                set bookmark_list_url to bookmark_list_url & ((characters -2 through -1 of ("0" & i) & " " & item i of bookmark_list_at) as text)
            end repeat
            set thebookmark to choose from list bookmark_list_url with prompt " Bitte URL auswählen... oder neue Hinzufügen... Oder löschen"
            -- /eine Liste bauen
        on error
            
            set bookmark_text to bookmark_abfragen()
            do shell script ("cd " & quoted form of myfolderx & "; echo " & quoted form of bookmark_text & " | openssl enc -aes-256-cbc -out bookmarks.txt -pass pass:" & userpass)
            set thebookmark to bookmark_text
            set newbookmarkfile to true
        end try
        
        if thebookmark as text = "••Hinzufügen••" then
            set bookmark_text to bookmark_text & (ASCII character 13) & bookmark_abfragen()
            do shell script ("cd " & quoted form of myfolderx & "; echo " & quoted form of bookmark_text & " | openssl enc -aes-256-cbc -out bookmarks.txt -pass pass:" & userpass)
        else if thebookmark as text = "••Löschen••" then
            -- eine Liste bauen
            set bookmark_text to do shell script "cd " & quoted form of myfolderx & "; cat bookmarks.txt | openssl enc -d -aes-256-cbc -in bookmarks.txt -pass pass:" & userpass
            set AppleScript's text item delimiters to ASCII character 13
            set bookmark_list_all to every text item of bookmark_text
            set bookmark_list_at to {}
            set AppleScript's text item delimiters to "@"
            repeat with b in bookmark_list_all
                set bookmark_list_at to bookmark_list_at & text item 2 of b
            end repeat
            set AppleScript's text item delimiters to ""
            set bookmark_list_url to {}
            repeat with i from 1 to (count of every item of bookmark_list_at)
                set bookmark_list_url to bookmark_list_url & ((characters -2 through -1 of ("0" & i) & " " & item i of bookmark_list_at) as text)
            end repeat
            set thebookmark to choose from list bookmark_list_url with prompt " Bitte Bookmark die gelöscht werden soll"
            -- /eine Liste bauen
            -- eine neue liste ohne die gelöschte bauen
            if thebookmark as text ≠ "false" then
                set indexdel to ((characters 1 through 2 of (thebookmark as text) as text) as integer)
                set bookmark_list_new to {}
                repeat with i from 1 to count of every item of bookmark_list_all
                    if i ≠ indexdel then
                        set bookmark_list_new to bookmark_list_new & item i of bookmark_list_all
                    end if
                end repeat
                -- /eine neue liste ohne die gelöschte bauen
                
                set AppleScript's text item delimiters to ASCII character 13
                set bookmark_text to bookmark_list_new as text
                set AppleScript's text item delimiters to ""
                do shell script ("cd " & quoted form of myfolderx & "; echo " & quoted form of bookmark_text & " | openssl enc -aes-256-cbc -out bookmarks.txt -pass pass:" & userpass)
                
            end if
        else
            --##/ bookmarks auslesen
            if thebookmark as text ≠ "false" then
                if newbookmarkfile = false then
                    set thebookmark to item ((characters 1 through 2 of (thebookmark as text) as text) as integer) of bookmark_list_all
                end if
                --##ftp upload
                repeat with this_item in these_items
                    upload(this_item, thebookmark)
                end repeat
                display dialog "Upload beendet" giving up after 5 with icon 1
                
                --##/ftp upload
            end if
        end if
        
    end open
    
    --## bookmarks auslesen
    on bookmark_abfragen()
        set ftpurl to ""
        set benutzername to ""
        set kennwort to ""
        set passtso to false
        repeat until passtso = true
            set displaystring to ftpurl
            set ftpurl to ""
            repeat until ftpurl ≠ "" and ftpurl contains "." and ((count of every character of ftpurl) > 3)
                display dialog "FTP URL, so etwas wie" & return & "meinedomain.de (ohne ftp://)" default answer displaystring
                set ftpurl to text returned of the result
            end repeat
            set displaystring to benutzername
            set benutzername to ""
            repeat until benutzername ≠ "" and benutzername does not contain " "
                display dialog "FTP Benutzername für :" & return & "ftp://" & ftpurl default answer displaystring
                set benutzername to text returned of the result
            end repeat
            set displaystring to kennwort
            set kennwort to ""
            repeat until kennwort ≠ "" and kennwort does not contain " "
                display dialog "FTP Kennwort für  :" & return & "ftp://" & benutzername & "@" & ftpurl default answer displaystring
                set kennwort to text returned of the result
            end repeat
            display dialog "Stimmt das so?:" & return & "ftp://" & benutzername & ":" & kennwort & "@" & ftpurl buttons {"Ja", "Nein", "cancel"}
            if (button returned of the result) as text = "Ja" then
                set passtso to true
                beep
            else if (button returned of the result) as text = "false" then
                tell me to quit
            end if
        end repeat
        return "ftp://" & benutzername & ":" & kennwort & "@" & ftpurl as text
    end bookmark_abfragen
    --##/ bookmarks auslesen
    
    
    --##ftp upload
    
    (*
    upload
    Uploads the given file or folder to the given remote ftp folder using "curl".
    If you need user/password to login to such server, append it to the URL. Eg:
    [URL]ftp://user:password@ftp.server.com/dir/[/URL]
    
    Parameters:
    filePath: file path, alias, posix path (a file or folder)
    remoteDir: ftp directory (eg: "ftp://ftp.server.com/foo/" or "ftp://user:password@ftp.server.com/dir/")
    
    Example:
    upload(alias "path:to:dir:", "ftp://usernameHERE:passwordHERE@ftp.serverHERE.com/html/docs/")
    *)
    to upload(filePath, remoteDir)
        global baseLocalFolder, baseRemoteFolder, ftpHome, ftpDir
        script nesteed
            to guessNewDir(f) -- "/path/to/footest" --> /footest
                set prevTids to AppleScript's text item delimiters
                set AppleScript's text item delimiters to POSIX path of parent's baseLocalFolder
                set f to item -1 of f's text items
                set AppleScript's text item delimiters to prevTids
                return f
            end guessNewDir
            to breakURL(d) --> "ftp://user:pass@ftp.server.com/html/docs/" --> {"ftp://user:pass@ftp.server.com", "/html/docs"}
                set prevTids to AppleScript's text item delimiters
                set AppleScript's text item delimiters to "/"
                set ftpHome to "" & items 1 thru 3 of d's text items
                try
                    set ftpDir to "/" & items 4 thru -1 of d's text items
                on error
                    set ftpDir to "/"
                end try
                set AppleScript's text item delimiters to prevTids
                return {ftpHome, ftpDir}
            end breakURL
            
            to processUnknownItem(f, remoteDir)
                set f to f as text
                if f ends with ":" then
                    processFolder(f, remoteDir)
                else
                    do shell script "curl -T " & quoted form of POSIX path of f & space & quoted form of remoteDir
                end if
            end processUnknownItem
            to processFolder(f, remoteDir)
                set newDir to guessNewDir(POSIX path of f) --> "/footest"
                try --> avoid existing dirs
                    if newDir is not "" then do shell script "curl -Q " & quoted form of ("MKD " & parent's ftpDir & newDir) & space & parent's ftpHome
                end try
                set itemList to list folder alias f without invisibles
                repeat with i in itemList
                    processUnknownItem(alias (f & i), parent's ftpHome & parent's ftpDir & newDir)
                end repeat
            end processFolder
        end script
        set wasError to false
        try
            set filePath to filePath as Unicode text
            if filePath does not contain ":" then set filePath to POSIX file filePath as Unicode text
            if remoteDir does not end with "/" then set remoteDir to remoteDir & "/"
            
            if filePath ends with ":" then --> mirror dir
                -- MAKE DIRECTORY "TEST" IN EXISTING "/HTML/DOCS"
                -- curl -Q "MKD /html/docs/test" [URL]ftp://user:pass@ftp.server.com[/URL]
                
                set baseLocalFolder to filePath
                set baseRemoteFolder to remoteDir
                set {ftpHome, ftpDir} to breakURL(remoteDir) of nesteed --> {"ftp://user:pass@ftp.server.com", "/html/docs"}
                
                processFolder(filePath, remoteDir) of nesteed
            else
                do shell script "curl -T " & quoted form of POSIX path of filePath & space & quoted form of remoteDir
            end if
        on error msg number n
            set wasError to true
        end try
        set baseLocalFolder to missing value
        set baseRemoteFolder to missing value
        set ftpHome to missing value
        set ftpDir to missing value
        if wasError then error msg number n
        return
    end upload
    --##/ftp upload
    
    --##Schlüsselbund Abfrage
    on getKey()
        set validKey to false
        set changedPassword to false
        tell application "Keychain Scripting"
            set theKeychain to current keychain
            tell theKeychain
                if locked then
                    tell me to display dialog "'Keychain Scripting' bittet gleich um das Passwort für den Schlüsselbund  '" & name of theKeychain & ¬
                        "' einzugeben. Das ist in Ordnung." buttons {"OK"} default button 1
                    unlock --provoziert Passworteingabeaufforderung vom Schlüsselbund
                end if
                set theKey to every Internet key of theKeychain whose name is myKeyName
                if theKey = {} then
                    set theKey to my makeKey()
                    set firstTime to true
                    set validKey to true
                else
                    set theKey to item 1 of theKey
                    set firstTime to false
                end if
            end tell --end tell theKeychain    
        end tell --end tell application "Keychain Scripting"
        repeat while not validKey
            tell application "Keychain Scripting" to set thePassword to the password of theKey
            try
                do shell script "sudo -k" --timeout our sudo ability so the following test is valid            
                do shell script "ls /private/var/root/" password thePassword with administrator privileges
                do shell script "sudo -k" --Zeitfenster von sudo schließen
                set validKey to true
            on error
                set thePassword to text returned of ¬
                    (display dialog "Das Administrator-Passwort für " & theAppName & " ist ungültig. Bitte korrigieren. Das Passwort wird bei der Eingabe zwar im Klartext angezeigt, gespeichert wird es im Schlüsselbund jedoch verschlüsselt." default answer "" with icon caution)
                set changedPassword to true
                set validKey to false
            end try
        end repeat
        if changedPassword then tell application "Keychain Scripting" to set the password of theKey to thePassword
        if firstTime then
            display dialog "Damit '" & theAppName & "' zukünftig ohne Ihr Zutun laufen kann, müssen Sie ihm Zugriffe auf den Schlüsselbund erlauben. Klicken Sie im ersten Dialog 'Immer erlauben' an, im zweiten 'Einmal erlauben'." buttons {"OK"} default button 1
        end if
        return theKey
    end getKey
    
    
    on makeKey()
        set validKey to false
        display dialog "'" & theAppName & "' fragt Sie jetzt nach Ihrem Administrator-Passwort, um es für zukünftige Nutzung sicher im Schlüsselbund abzulegen. Diese Abfrage erscheint dann nicht mehr."
        repeat while not validKey
            set thePassword to text returned of (display dialog "Das Passwort wird bei der Eingabe zwar im Klartext angezeigt, gespeichert wird es im Schlüsselbund jedoch verschlüsselt. Geben Sie Ihr Administrator-Passwort ein:" default answer "" with icon caution)
            try
                do shell script "sudo -k" --Zeitfenster von sudo schließen
                do shell script "ipfw list" password thePassword with administrator privileges
                do shell script "sudo -k" --Zeitfenster von sudo schließen            
                set validKey to true
            on error
                display dialog "Das Passwort ist ungültig. Bitte geben Sie ein anderes ein." buttons {"OK"} default button 1 with icon caution
                set validKey to false
            end try
        end repeat
        tell application "Keychain Scripting"
            activate
            set theKeychain to current keychain
            set username to system attribute "USER"
            set theComment to "angelegt von '" & theAppName & " " & (theAppVersion as text) & "'"
            try
                set myKey to first Internet key whose name is myKeyName
                delete myKey -- To impove by setting directly with new password when i'll find the problem
            end try
            set myKey to (make new Internet key at theKeychain with properties ¬
                {name:myKeyName, description:keyDescription, account:username, comment:theComment, password:thePassword})
        end tell --end tell application Keychain Scripting
        return myKey
    end makeKey
    
    --##/Schlüsselbund Abfrage
     
    plaetzchen gefällt das.
  3. plaetzchen

    plaetzchen Kaiserapfel

    Dabei seit:
    21.10.05
    Beiträge:
    1.729
    Cool das brauchte ich. Werde es ein wenig anpassen und dann kann ich das gut gebrauchen! Danke!
     

Diese Seite empfehlen