we use our ftp-server a lot to make files available for clients. What we do is this:
We copy the file(s) to our FTP server
we create a download-link to that file, complete with username and password (type it by hand)
we mail the link to whomever it concerns
once the link is clicked, the download will start.
What I would like is a script that creates that link, so the login and password are fixed,
but I would like to have the filename (with full path) to appear in a new mail-message.
i think i can get you started on this. here is a script that will let you hard code the user and password that you use all the time. it will ask you for the filename and then supply the path you are looking for. now if you can script Mail to open up a new message and supply this as the text of the message i think you should be all set:
global theFile
global theUser
global thePass
global theFTPServer
global theURL
set theUser to "username"
set thePass to "password"
set theFTPServer to "[url=ftp://ftp.our-ftp-server.nl]ftp.our-ftp-server.nl[/url]"
set fileMsg to "What is the name of the file?"
set theFile to text returned of (display dialog fileMsg default answer "")
set theURL to "ftp://" & theUser & ":" & thePass & "@" & theFTPServer & "/" & theFile
display dialog theURL -- replace this with the Mail scripting.
thnx for you reply, but maybe my question wasn’t clear enough. Thinking about what I want, and using the little knowledge I have about “Applescript-in-a-week”, it could be simpler.
What if I drop a file on a script, and the script creates a new mail message with the fixes part of the adress,
and adds the filename. Do I still make sense???
ok, no problem. we add a few things but the basics are already done. i don’t know the Mail dictionary so i’m not sure about opening a message, but this should get you started:
on run
display dialog "To use this script, please drag a file onto its Finder icon" buttons {"Cancel"} default button 1
end run
on open draggedItem
set theUser to "username"
set thePass to "password"
set theFTPServer to "[url=ftp://ftp.our-ftp-server.nl]ftp.our-ftp-server.nl[/url]"
tell application "Finder"
set f to draggedItem as string
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set howMany to (count text items of f)
set theFile to text item howMany of f
set AppleScript's text item delimiters to ASTID
end tell
set theURL to "ftp://" & theUser & ":" & thePass & "@" & theFTPServer & "/" & theFile
display dialog theURL -- replace this with the Mail scripting.
end open
you’ll need to save the above as an ‘Application’ to get it to work with a dragged file.
i had a few minutes after lunch so i added the mail part:
on run
display dialog "To use this script, please drag a file onto its Finder icon" buttons {"Cancel"} default button 1
end run
on open draggedItem
set theUser to "username"
set thePass to "password"
set theFTPServer to "[url=ftp://ftp.our-ftp-server.nl]ftp.our-ftp-server.nl[/url]"
tell application "Finder"
set f to draggedItem as string
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set howMany to (count text items of f)
set theFile to text item howMany of f
set AppleScript's text item delimiters to ASTID
end tell
set theURL to "ftp://" & theUser & ":" & thePass & "@" & theFTPServer & "/" & theFile
tell application "Mail"
activate
set theSubject to "New File is ready for you!" as string
set myMessage to make new outgoing message with properties {content:theURL, subject:theSubject, visible:true}
end tell
end open
it works ok, but there are some caveats. i may not do any more with it though. so be aware:
it depends on you to put the file in the right place on the FTP server. you can change the path pretty easily in the script though
if you drag folders on it, it does not work
if you drag multiple files on it, it only gets the first one
it does not address the email. i figured you may want to do that by hand anyway
no problem. just keep in mind that the script has it’s limitations. if you are learning, you might regard it as a rough draft. if you ever improve upon it, post the improvements here.
i regard it as a prototype for something i might seriously do.