AppleScriptでFTP

| コメント(0) | トラックバック(0)

■■■このスクリプトについて■■■
AppleScriptのFTPです。
実行してホームページのルートフォルダを選択すると指定時間内のファイルをアップロードします。

■■■インストール方法■■■
特にありません。お好きな場所にコピーしてください。

■■■使い方■■■
upload.scptをAppleScriptエディタで開き下記設定をします。
----------ここから---------
property user : "xxxxxx" --FTPのログインID
property passwd : "xxxxxxxxxx" --FTPのログインパスワード
property serverRoot : "ftp://xxxx.xxxxxx.ne.jp" --FTPアドレス
property destDir : serverRoot & "/www/" --アップするパス
property myhours : 2 --何時間前より新しいものをアップ
property labelflg : 1 --ラベルがついていないものをアップ(0にしたらラベルは無視する)
----------ここから---------
スクリプトを実行するとフォルダ選択ダイアログが出るのでホームページのルートフォルダを選択します。
条件にあったファイルをアップロードします。ディレクトリが無ければ作成します。
すべて終わればアップロードしたファイルの一覧を表示します。
スピードはあんまり早くないですが手軽に使えますのでけっこう便利です。

ダウンロードはコチラ:ftp.zip
else12

property user : "xxxxxx" --FTPのログインID
property passwd : "xxxxxxxxxx" --FTPのログインパスワード
property serverRoot : "ftp://xxxx.xxxxxx.ne.jp" --FTPアドレス
property destDir : serverRoot & "/www/" --アップするパス
property myhours : 2 --何時間前より新しいものをアップ
property labelflg : 1 --ラベルがついていないものをアップ(0にしたらラベルは無視する)

on run
	global mytime
	global mymsg
	set mymsg to ""
	set mytime to my (current date)
	set mytime to the (mytime) - (myhours * hours)
	set myFol to choose folder with prompt "rootディレクトリのフォルダを選択"
	repeat with myFile in list folder myFol without invisibles
		set targetFile to (myFol as string) & (myFile) as alias
		my upload(targetFile, "")
	end repeat
	display dialog "アップロード完了" & return & mymsg
end run

on open theList
	--ドロップする場合はrootディレクトリをドロップします。
	global mytime
	global mymsg
	set mymsg to ""
	set mytime to my (current date)
	set mytime to the (mytime) - (myhours * hours)
	set myFol to item 1 of theList
	repeat with myFile in list folder myFol without invisibles
		set targetFile to (myFol as string) & (myFile) as alias
		my upload(targetFile, "")
	end repeat
	display dialog "アップロード完了" & return & mymsg
end open

on upload(targetFile, dirname)
	global mytime
	global mymsg
	tell application "Finder"
		set sindex to label index of targetFile
		set mykind to kind of targetFile
		set fname to name of targetFile
		set ext to name extension of targetFile
		set ftime to modification date of targetFile
	end tell
	--ラベルがついていないものだけをアップ
	set upflg to true
	if labelflg is 1 then
		if sindex is not 0 then
			set upflg to false
		end if
	end if
	if upflg is true then
		if mykind is "フォルダ" then
			set myFol to targetFile
			set fPath to quoted form of (POSIX path of targetFile as Unicode text)
			repeat with myFile in list folder myFol without invisibles
				set targetFile to (myFol as string) & (myFile) as alias
				my upload(targetFile, dirname & fname & "/")
			end repeat
		else
			set upflg to false
			if mytime < ftime then
				if ext is "html" or ext is "php" then
					set upflg to true
				else if ext is "inc" then
					set upflg to true
				else if ext is "jpeg" or ext is "jpg" then
					set upflg to true
				else if ext is "gif" or ext is "png" then
					set upflg to true
				end if
				if upflg is true then
					set fPath to quoted form of (POSIX path of targetFile as Unicode text)
					set myScript to "curl --ftp-create-dirs -T " & fPath & " -u " & user & ":" & passwd & " " & destDir & dirname
					--display dialog myScript
					try
						--★テストする場合は下記をコメントにする
						set myResult to (do shell script myScript)
						set mymsg to mymsg & fname & "/"
					on error
						display dialog "シェルスクリプトのエラーです" & fPath
					end try
				end if
			end if
		end if
	end if
end upload

トラックバック(0)

トラックバックURL: http://www.adg7.com/mt/mt-tb.cgi/1001

Comments are nofollow setting

コメントする

エントリー一覧

OpenID対応しています OpenIDについて
Powered by Movable Type 7.902.0
漢字イラストロジック-脳トレ京
FREE ONLINE SUDOKU