2012-02-17 9 views
0

私は以下のスクリプトを持っています(個人情報を削除するように変更されました)。Fetchとapplescriptを使用して、どのようにすべてのファイルをダウンロードしますか?

-- This line is for testing. 
set the clipboard to "1234567890" 

set loginName to "username" 
-- Password is stored in KeyChain (you need to do manually). 

-- Create Remote path 
set folderNumber to the clipboard as string 
set subdir1 to character 1 of folderNumber 
set subdir2 to character 2 of folderNumber 

set remotePath to "/files/" & subdir1 & "/" & subdir2 & "/" & folderNumber 

-- Create Local path 
set homeFolder to (path to home folder) as string 
set localPath to homeFolder & "LOCALSTORAGE" as string 
set localStorage to localPath & ":" & folderNumber & ":" as string 

-- Create Local file 
tell application "Finder" 
    try 
     make new folder at localPath with properties {name:folderNumber} 
    on error e number n 
     -- Do nothing. 
    end try 
end tell 

-- Connect to FTP 
tell application "Fetch" 
    activate 
    set tWindow to make new transfer window at beginning with properties {hostname:"ftpServerAddress", username:loginName, initial folder:remotePath} 

    tell window tWindow 
     download every remote item to beginning of alias localStorage 
     close window 
    end tell 

    quit 
end tell 

-- Open folder 
tell application "Finder" 
    open localStorage 
end tell 

スクリプトを実行すると、次の行が失敗します。

download every remote item to beginning of alias localStorage 

次のように私が手にエラーがある:

error "Fetch got an error: Can’t get every remote item of window (transfer window id 232280960)." number -1728 from every remote item of window (transfer window id 232280960)

誰もが、エラーが何を意味するかまたはそれを修正する方法を知っていますか?私は多くの運がなければフェッチのウェブサイトを試みました。 "Fetch" btwはFetch FTPクライアントです。

答えて

2

は、まず、(例えばlog tWindow's remote itemsようなlog文を追加し、それらを取得することができたかどうかをスクリプトエディタのイベントログで検索することで)あなたが作成しているremotePathが実際に存在することを確認する必要があります。

パスが正しい場合は、リストオブジェクト(every remote item...)への参照でdownloadコマンドを使用していることが問題だと思います。ドキュメントでは、コマンドは単一項目の指定子を要求します。

download specifier : the remote file, remote folder, shortcut, or url to download

そのため、項目をループする必要があります。 The snippet belowは私のために完璧に動作します:

-- my settings for testing 
set theHost to "ftp.fetchsoftworks.com" 
set loginName to "anonymous" 
set remotePath to "/example/" 
set localStorage to ((path to home folder) as text) & "LOCALSTORAGE:1234567890:" 

-- Connect to FTP 
tell application "Fetch" 
    activate 
    set tWindow to make new transfer window at beginning with properties {hostname:theHost, username:loginName, initial folder:remotePath} 
    set localStorage to (localStorage as alias) 
    repeat with theItem in tWindow's remote items 
     try 
      download theItem to localStorage 
     end try 
    end repeat 

    close tWindow 
    quit 
end tell 
+0

ありがとう!それは動作します。また、「ミラーフォルダ」オプションのappleScriptを記録できることも発見しました。それから、私はすべてを引き抜くという命令も得ました。 –

1

downloadにリストを渡しても問題はありません。

tell window tWindow 
    download every remote item to beginning of alias localStorage 
    close window 
end tell 
  1. tellブロックは、一般的なwindowオブジェクトではなく、transfer windowに囲まれたコマンドを指示し、そして一般的なwindowオブジェクトはリモートの項目が含まれていません。しかし、元のコードを持つ2つの問題があります。
  2. downloadコマンドのtoパラメータは、エイリアスであり、挿入場所ではありません(例:beginning of ...)。

これは動作するはずです:

tell tWindow 
    download every remote item to alias localStorage 
    close 
end tell 
+0

ありがとうございます。それは私のために別の問題を修正した。 :) –

関連する問題