并在文件复制到文件夹时自动上传到ftp

并在文件复制到文件夹时自动上传到ftp

本文介绍了AppleScript用于更改前缀,并在文件复制到文件夹时自动上传到ftp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个AppleScript,它允许我自动在文件上添加前缀并将其复制到特定文件夹(在OS X El Capitan下用作文件夹操作)时上传到ftp服务器.

I am programing an AppleScript that allows me to automatically put a prefix to a file and upload it to an ftp-server when it is copied to a specific folder (used as a folder action under OS X El Capitan).

我要工作的是该文件会自动上传,但是当我尝试实现它应该添加一个前缀(特别是unix时间戳)时,它既不会更改文件名,也不会将其上传到ftp-目录.

What I get to work is that the file is automatically uploaded, but when I try to implement that it should add a prefix (specifically a unix timestamp), it won't change either the filename nor uploading it to the ftp-directory.

这是我现在的代码:

property uploadftp : "ftp://user:password«ftpxyz.de/directory/" --this will be changed to the real one
set nowSeconds to ((current date) - (date ("1/1/1970")) - (time to GMT)) as miles as string
set timestamp to nowSeconds & "_"
set Tag to timestamp
on adding folder items to this_folder after receiving added_items
    set thelist to ""
    repeat with i in added_items
        set thelist to thelist & return & i & ","
        try
            set theFiles to thelist
            repeat with aFile in theFiles
                set name of aFile to Tag & name of aFile
            end repeat
            do shell script "curl -T " & quoted form of POSIX path of i & space & quoted form of uploadftp
        on error e number n
            display dialog "Error: " & e & "Number: " & n
        end try
    end repeat
    display dialog "Dateien empfangen: " & (count added_items) & return & "Ordner: " & POSIX path of this_folder & return & "Dateien: " & thelist
end adding folder items to

推荐答案

我怀疑该脚本是否可以正常工作.

I doubt that the script works at all.

主要问题是事件处理程序外部的代码不会在运行时执行.

The main issue is that code outside the event handler won't be executed at runtime.

尝试一下:

property uploadftp : "ftp://user:password«ftpxyz.de/directory/" --this will be changed to the real one

on adding folder items to this_folder after receiving added_items

    set timestamp to ((current date) - (date ("1/1/1970")) - (time to GMT)) as miles as string

    set thelist to {}
    repeat with aFile in added_items
        try
            set fileName to name of (info for aFile)
            set newFileName to timestamp & "_" & fileName
            set end of thelist to fileName
            do shell script "curl -T " & quoted form of POSIX path of aFile & space & quoted form of (uploadftp & newFileName)
        on error e number n
            display dialog "Error: " & e & "Number: " & n
        end try
    end repeat
    set saveTID to AppleScript's text item delimiters
    set AppleScript's text item delimiters to ","
    set receivedFiles to thelist as text
    set AppleScript's text item delimiters to saveTID
    display dialog "Dateien empfangen: " & (count added_items) & return & "Ordner: " & POSIX path of this_folder & return & "Dateien: " & receivedFiles
end adding folder items to

这篇关于AppleScript用于更改前缀,并在文件复制到文件夹时自动上传到ftp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 05:37