upload by filetype

i would like to be able to upload only certain files by ftp to a server, based on filetype. for example if i wanted to upload a .jpg every time i save one to a folder but not .mpg

i use cyberduck for ftp and have edited this script: http://svn.cyberduck.ch/trunk/AppleScript%20Samples/Upload%20Sample.scpt

or

--  Copyright (c) 2004 David Kocher. All rights reserved.
--  http://cyberduck.ch/
--
--  This program is free software; you can redistribute it and/or modify
--  it under the terms of the GNU General Public License as published by
--  the Free Software Foundation; either version 2 of the License, or
--  (at your option) any later version.
--
--  This program is distributed in the hope that it will be useful,
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--  GNU General Public License for more details.
--
--  Bug fixes, suggestions and comments should be sent to:
--  dkocher@cyberduck.ch

on adding folder items to this_folder after receiving added_items
	set theServer to "example.net"
	set theUser to "username"
	set theProtocol to "ftp"
	set theUploadFolder to "upload"
	
	set the item_count to the number of items in the added_items
	if the item_count is greater than 0 then
		with timeout of 300 seconds
			tell application "Cyberduck"
				set theBrowser to (make new browser)
				tell (theBrowser)
					set encoding to "UTF-8"
					connect to theServer with protocol theProtocol as user theUser with initial folder theUploadFolder
					repeat with theFile in added_items
						upload item theFile
					end repeat
					disconnect
				end tell
			end tell
		end timeout
	end if
end adding folder items to

it works perfectly but uploads every file. sorry i have never scripted anything before, editing a field in a script is ok but i don’t know how to add to it…

cheers

edit: if anyone can help it’d be great to be able to move the file, or copy then delete original. thanks

Hi,

I don’t use Cyberduck, so I can’t test this,
you have to change the repeat block


.
repeat with theFile in added_items
	if name extension of (info for theFile) is "jpg" then 
		upload item theFile
		tell application "Finder" to delete theFile
	end
end repeat
.

thank you very much! its almost perfect.

it works just fine, it uploads only the filetypes i specified. the only problem is downloading any file to the folder will cause cyberduck to open, or open a new window if it is already open, even if it does not upload anything. maybe its the order in the script? is there a way to check the filetype rule matches before opening the app, so it doesn’t load cyberduck for no reason?

thanks again, i really appreciate your help

You can do the whole thing without any FTP client


property theServer : "[url=ftp://ftp.example.net/]ftp.example.net/[/url]"
property theUser : "username"
property thePassword : "¢¢¢"
property theUploadFolder : "upload/"

on adding folder items to this_folder after receiving added_items
	repeat with theFile in added_items
		if name extension of (info for theFile) is "jpg" then
			do shell script "curl " & quoted form of (theServer & theUploadFolder) & " -u " & theUser & ":" & thePassword & " -T " & quoted form of POSIX path of theFile
			tell application "Finder" to delete theFile
			-- or to delete immediately
			-- do shell script "rm " & quoted form of POSIX path of theFile
		end if
	end repeat
end adding folder items to

Note: consider the slashes in theServer and theUploadFolder

thanks for the reply, unfortunately that script doesn’t seem to work for me. it doesn’t upload the file or delete it. i have this:

property theServer : "[url=http://www.mydomain.com/]www.mydomain.com/[/url]"
property theUser : "username"
property thePassword : "password"
property theUploadFolder : "downloads/"

on adding folder items to this_folder after receiving added_items
	repeat with theFile in added_items
		if name extension of (info for theFile) is "filetype" then
			do shell script "curl " & quoted form of (theServer & theUploadFolder) & " -u " & theUser & ":" & thePassword & " -T " & quoted form of POSIX path of theFile
			tell application "Finder" to delete theFile
			-- or to delete immediately    
			-- do shell script "rm " & quoted form of POSIX path of theFile   
		end if
	end repeat
end adding folder items to

i don’t know if the script would tell Finder to delete the file even if the upload process before that had failed, but it doesn’t do either action. thanks for trying tho, i appreciate the help!

it copies only files with name extension filetype, do you really have files named myfile.filetype?

no no, i edited that for the example. the “filetype” is actually the extension, not the word filetype

then there is something wrong with your server access data or you haven’t properly attached the folder action

I’ve just successfully tested this script (commented out the folder action handler to get some error messages)

property theServer : "[url=http://www.mydomain.com/]www.mydomain.com/[/url]"
property theUser : "username"
property thePassword : "password"
property theUploadFolder : "downloads/"

-- on adding folder items to this_folder after receiving added_items
set added_items to {choose file}
repeat with theFile in added_items
	if name extension of (info for theFile) is "jpg" then
		do shell script "curl " & quoted form of (theServer & theUploadFolder) & " -u " & theUser & ":" & thePassword & " -T " & quoted form of POSIX path of theFile
		tell application "Finder" to delete theFile
		-- or to delete immediately    
		-- do shell script "rm " & quoted form of POSIX path of theFile   
	end if
end repeat
-- end adding folder items to

i copy-pasted your script and edited the properties, and the filetype, but it still does nothing i’m afraid, even after copy-pasting the information for the properties from the working cyberduck script to make sure i hadn’t spelt something wrong or used the wrong syntax. i used exactly the same method to attach the action too. i thought it might be blocked by ClamAV which monitors that folder specifically but it made no difference. perhaps your script works fine but something else on my mac is stopping it from working?

i’ve gone back to using the cyberduck script, partly because it works for me and also for intergration with growl and things i use. i really appreciate your help with the scripts tho, i don’t want to appear ungrateful!

if i can get the cyberduck script to do what it does without either launching for a filetype which won’t be uploaded, and also opening a new window every time even when there is one already opened (i end up with about 10-20 windows open sometimes) OR close the window once the transfer is complete, i will be happy with that

thanks again StefanK