ftp and connecting to server

How do you specify the second folder?
can we specify it the same way we specify the first folder (ask the user to select the distance folder)! And it makes sense to copy all file instead of copying specific one’s.

I recall you mentioned that I should be connected to the server. let’s say it’s not, is it that hard to connect to ask the user to connect to a specfic server? This one is a curious question more than a requirement!

thanks.

something else Stefan, I will continue to post on this site for a while, hope that’s OK with you :slight_smile:
so, even though I am not as a good scripter as Stefan, but would like to help, so Stefan and other , please let me know how I can help to contribute in this site.

thanks.

I hope, this does everything.
Caution: At the end all files and folders including subfolders of folder 1 on the server will be deleted


property NameList : {"Server1", "Server2", "Server3"}
property ServerList : {"ftp.myServer1.com", "[url=ftp://ftp.myServer2.com]ftp.myServer2.com[/url]", "[url=ftp://ftp.myServer3.com]ftp.myServer3.com[/url]"} --ftp server
property pathList : {"/pub/jpg/", "/pub/gif/", "/pub/png/"}
property usernameList : {"¢¢¢¢¢", "¢¢¢¢¢", "¢¢¢¢¢"} --server_username
property passwordList : {"¢¢¢¢¢", "¢¢¢¢¢", "¢¢¢¢¢"} --server_password

set tempFolder to POSIX path of ((path to temporary items as Unicode text) & "curl_temp_folder:")
try
	do shell script "rm -rf " & quoted form of tempFolder
end try
do shell script "mkdir " & quoted form of tempFolder

set chosenServer to (choose from list NameList with prompt "choose one or multiple servers" with multiple selections allowed)
if chosenServer is false then return

repeat with i from 1 to count chosenServer
	repeat with j from 1 to count NameList
		if item i of chosenServer is item j of NameList then exit repeat
	end repeat
	set ftpserver to item j of ServerList
	set ftppath to item j of pathList
	set server_username to item j of usernameList
	set server_password to item j of passwordList
	
	if ftppath does not end with "/" then set ftppath to ftppath & "/"
	set servername to ftpserver & ftppath
	set theFiles to paragraphs of (do shell script "curl -l " & servername & " -u " & server_username & ":" & server_password)
	set DLfiles to choose from list theFiles with prompt "choose one or multiple files to download:" with multiple selections allowed
	set FileServers to choose URL showing File servers
	set theServer to (mount volume FileServers) as alias
	set destfolder1 to (choose folder with prompt "choose destination folder 1")
	set dFname1 to name of (info for destfolder1)
	set destfolder2 to (choose folder with prompt "choose destination folder 2")
	set dFname2 to name of (info for destfolder2)
	repeat with i in DLfiles
		set serverURL to quoted form of (servername & i)
		set destPath to quoted form of (tempFolder & i)
		do shell script "curl -o " & destPath & " -u " & server_username & ":" & server_password & " " & serverURL
	end repeat
end repeat
tell application "Finder" to set fileList to items of (POSIX file tempFolder as alias)
set c to count fileList
repeat with i in fileList
	if (name extension of (info for (i as alias)) is "zip") then
		tell application "StuffIt Expander" to expand {i as alias} into destfolder1 
	else
		tell application "Finder" to move (i as alias) to destfolder1
	end if
end repeat
quit application "StuffIt Expander"
display dialog (c as string) & " file(s) downloaded" buttons {"Done"} default button 1
set toCopy to button returned of (display dialog "Copy all files from folder " & dFname1 & " to folder " & dFname2 & "?" buttons {"No", "Copy"} default button 2)
if toCopy is "Copy" then
	tell application "Finder" to duplicate (get items of destfolder1) to destfolder2
end if
set toDelete to button returned of (display dialog "Delete all files in folder " & dFname1 & "?" buttons {"No", "Delete"} default button 2)
if toDelete is "Delete" then do shell script "rm -rf " & quoted form of POSIX path of destfolder1 & "*"
try
	do shell script "rm -rf " & quoted form of tempFolder
end try

I will tell you one wierd instance I am running into, when tryiong to connect to server and mount to volume, I get the message:
-File some object wasn’t found.
and this section is highlighted (mount volume FileServers)

This only happens for one server though! any idea why is this happening!

Unfortunately no, although the script seems quite complex, it’s very straight and simple without any error trappings.
I’ve just tested it with my PowerBook as the file server and everything worked fine.

If all servers are known, you can also use further lists with address, user name and password to connect directly to the server(s).

If all servers are known, you can also use further lists with address, user name and password to connect directly to the server(s).

would you mind showning me how to do that. and I promise you I will not ask anymore questions on this script.

p.s: no one meniotned anything about how I can help in this site as a thank you to Stefan and others.

Hi Bill,

it’s almost the same like the part to choose the server(s) to load data from

property FileServerList : {"FileServer1", "FileServer2", "FileServer3"} --Fileserver
property VolumeList : {"Volume1", "Volume2", "Volume3"}
property unList : {"¢¢¢¢¢", "¢¢¢¢¢", "¢¢¢¢¢"} --Fileserver_username
property pwList : {"¢¢¢¢¢", "¢¢¢¢¢", "¢¢¢¢¢"} --Fileserver_password

set chosenFileServer to (choose from list FileServerList with prompt "choose a Fileserver")
if chosenFileServer is false then return

repeat with i from 1 to count FileServerList
    if item 1 of chosenFileServer is item i of FileServerList then exit repeat
end repeat

set cmd to "afp://" & item i of unList & ":" & item i of pwList & "@" & item i of FileServerList & ".local" & "/" & item i of VolumeList
try
    mount volume cmd
on error e number n
    display dialog "Error number " & (n as string) & ":" & return & e
end try

put it in the script replacing these two lines:

set FileServers to choose URL showing File servers set theServer to (mount volume FileServers) as alias

Never mind! You’re welcome :slight_smile:

Thanks again for your help.

Even though the server name, volume, pass, and user name are correct. I keeo getting an “error number -35 Disk (volume_name) was not found”.

Something else I like to mention. How can I protect my script from others. I mean, someone can open my script and see my user names and passwords for server connections and FTP connections!

thanks.

the string must be (assuming an AFP-Server):

afp://username:password@servername.local/Volume

servername.local is the name of the server as it appears in the choose URL window

or

afp://username:password@xxx.xxx.xxx.xxx/Volume

you can check the string with

set cmd to "afp://" & item i of unList & ":" & item i of pwList & "@" & item i of FileServerList & ".local" & "/" & item i of VolumeList
display dialog cmd

This can be quite difficult. Either you save a copy(!!!) of your script as run only,
so nobody can open the script (also yourself, that’s the reason for a copy)
or you must integrate a encryption routine and save the encrypted data in an external file

after looking at the command displayed, I found my problem. I have left .local the same. I see how the code

display dialog cmd

is very helpful in debugging.

This is wonderful :slight_smile: but, how can I run a run only script!

Can I turn this script into an application? if so, how?

As you notice, I am learning to copy quotes :slight_smile:

Just save the script as plain script, application or application bundle with option “Run Only”.
I’d like to repeat it: A script, saved as Run Only, can not be opened and edited. So use always a copy

understood.

Stefan, Thanks sooooo much for all your help.