in the code below, you have to enter the path list in the code. how can you allow the user to enter a different path list if he wants the when he tries to connect to FTP.
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 ftppath to item i of pathList
...
...
I know you had another FTP thread going on here, which I didnt read :(, but perhaps that would help me here… What are you asking exatcly because I feel Im missing something.
Assuming Im not you could just use a choose from list, but add “other” to the choices. Then evaluate, if other prompt user for the path with a display dialog.
you find it in my first version of the script in the other thread:
...
set ftppath to text returned of (display dialog "Enter path of FTP-Server (slash separated):" default answer "/")
if ftppath does not end with "/" then set ftppath to ftppath & "/"
...
Thansks Stefan. we changed that script so many times, I forgot!
can you do the same for the mounting? to allow the user to enter his/her user name and password (can we remember the script for a particular user?). please refer to script
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
sorry for so many questions, but I figured I will learn a lot to start other threads and ask questions.
This a lot better. Thanks. I think users will find it uncomfortable to be asked about their password!
couple things I have noticed in the final script:
when the server volume is mounted, I get an error! and if I press ok or cancel, nothing happens and the script continues working fine.
If the server volume was mounted, it would make sense if a message comes up that will tell the user, this volume is mounted with only the OK button appearing on the message.
When the user connects to the FTP, they can’t navigate particular folders. can we allow the user to navigate to a certain folder if they are not sure what path theu have to select. one FTP I looked at changes the path almost everyday, so this will help a lot.
I am trying to display a message at the end that will tell the user “thanks for using the script”, but will disappear in seconds by itself. Or maybe will only show the OK button.
Here is the modified script:
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/gif/", "/pub/gif/", "/pub/png/"}
property usernameList : {"¢¢¢¢¢", "¢¢¢¢¢", "¢¢¢¢¢"} --server_username
property passwordList : {"¢¢¢¢¢", "¢¢¢¢¢", "¢¢¢¢¢"} --server_password
--server list
property FileServerList : {"FileServer1", "FileServer2", "FileServer3"} --Fileserver
property VolumeList : {"Volume1", "Volume2", "Volume3"}
property unList : {"¢¢¢¢¢", "¢¢¢¢¢", "¢¢¢¢¢"} --Fileserver_username
property pwList : {"¢¢¢¢¢", "¢¢¢¢¢", "¢¢¢¢¢"} --Fileserver_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
--allow user to select which path they want to connect to
set ftppath to text returned of (display dialog "Enter path of FTP-Server (slash separated):" default answer "/")
if ftppath does not end with "/" then set ftppath to ftppath & "/"
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
--this section allows you to connect to a server directly
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 FileServerList & ".hq.vitalsource.com" & "/" & item i of VolumeList
--set cmd to "afp://" & item i of unList & ":" & item i of pwList & "@" & item i of FileServerList & ".hq.vitalsource.com" & "/" & item i of VolumeList
--set cmd to "afp://" & item i of unList & ":" & item i of pwList & "@" & item i of FileServerList & "/" & item i of VolumeList
--added for debugging
display dialog cmd
try
mount volume cmd
on error e number n
display dialog "Error number " & (n as string) & ":" & return & e
end try
--end of server connnect markup
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
display dialog "Thank you for using this script"