Script needed for copying files from FTP to location on system

Hi,

I need a script that moves incoming files from my FTP to a location on my sy
stem and once moved, deletes them from my FTP.

I am already this far:

set {f1, f2} to {“Volumes/ftp.enfocus.com/incoming/PA Test JeroenD”, “/Users
/JeroenD/Desktop/FTP Test”}
tell application “Finder”
move every file of folder f1 to folder f2
end tell

Error says: Impossible to obtain every file of folder

How come? End what about the deleting part? Thanks!

Try this:


set {f1, f2} to {"Volumes:ftp.enfocus.com:incoming:PA Test JeroenD" as alias, "Macintosh HD:Users
:JeroenD:Desktop:FTP Test" as alias}
tell application "Finder"
	move every file of folder f1 to folder f2
end tell

Now for the “how come?” bit… :wink:

Finder will usually understand a variety of path identifiers, including (in no particular order):

As you’ve discovered, what doesn’t work in this context is a Unix-type path:

The bridge between Unix and traditional Mac forms is Posix: Unix paths can be coerced to other classes via Posix file, while Posix path facilitates conversion in the other direction.

So, if you need Finder to do some work, use a form other than a Posix path (as, for example, j already suggested). If you have no choice in what you’re starting out with (such as when another operation has already served up Posix paths), then you’ll need to add a further step - something like:


set {f1, f2} to {"Volumes/ftp.enfocus.com/incoming/PA Test JeroenD", "/Users/JeroenD/Desktop/FTP Test"}
set {f1, f2} to {f1 as POSIX file, f2 as POSIX file}
tell application "Finder" to move folder f1's files to folder f2


Hi.

Just taking notes here… might need this information… in case I have an opportunity to share it… :rolleyes:

thanks kai. :slight_smile:

superb, it works perfectly, thank u all

Now i need the files on the FTP to be deleted.
As soon as there is a new file on the FTP is needs to be copied to the folder
so i was thinking about an “every 5 minutes re-run” (or something else)

If this could be possible it would be fantastic!!!

If you plan to do a fair amount of scheduling, then it might be worth checking out cron(8), crontab(1) and crontab(5). (And if the technical stuff causes your eyes to glaze over, take a look, also, at CronniX - now available as a Universal binary.)

However, for occasional jobs like this, my own personal preference would be to use a script - saved as a stay-open application, and containing an idle handler.

In its simplest form*, such a script might look something like the example below. (* So simple, in fact, that I threw in the random voi©e handler, in the hope of making it slightly more interesting. And in case you were wondering, most of the routine is workaround for discrepancies between folder and voice names, such as: “BadNews”/“Bad News”, “GoodNews”/“Good News” and “Organ”/“Pipe Organ”.)

Save as: Stay Open Application


on idle
	(* your script here *)
	say "Are you still playing on that computer?" using |random voi©e|() (* demo code only *)
	5 * minutes (* make sure this is the handler's final statement *)
end idle

(* pay no serious attention to the rest: just for fun... *)

on |random voi©e|()
	set p to path to voices as Unicode text
	set t to read file (p & some item of (list folder p without invisibles) & ":Contents:Resources:VoiceDescription")
	(t's text 18 thru (17 + (ASCII number t's character 17)))
end |random voi©e|


To launch the script application at login, simply add it to your Account’s Login Items (in System Preferences).

If you’d additionally like to run it as a background-only application, one of the easiest ways would be to convert it using Drop Script Backgrounder.

:slight_smile: