Hello guys,
i’ve needed to simulate one of my daily tasks at work which is copy backup files from remote hosts to my computer, so i’ve write this script which helped me a lot! it took me around 2 days to get it done as i am so new to apple script.
hope it can help anyone of you, also any comments/updates are highly appreciated!
--Password Protection
--password is "yourpassword"
repeat
display dialog "Please enter the Password:" default answer "" with hidden answer
set Passwd to text returned of result
if Passwd = "yourpassword" then exit repeat
end repeat
set done to {} --> working hosts
set failed to {} --> unreachable hosts
set done1 to {} --> working hosts 1
set failed1 to {} --> unreachable hosts 1
set Cmd to {":/*.backup /Users/ahdisml/Desktop/MTBackup"} --> excuted command on host, in my case remote file is on "/' with ".backup" ext., change it whatever you like along with the destination.
set Directory to {"Mac HD:Users:ahdisml:Desktop:MTBackup:"} --> local destination
repeat with IPs in {"192.168.1.247", "172.16.20.203"} -->list of IP addresses
try
set sftp to do shell script "sftp user@" & IPs & Cmd -- put your user name before the @
set end of done to contents of return & "-" & IPs
on error
set end of failed to contents of return & "-" & IPs
close sftp
end try
end repeat
set d to display dialog {"Done at: " & done & "
Failed at: " & failed} buttons {"Close", "Show Files"}
if button returned of d is "Show Files" then
tell application "Finder"
open Directory
end tell
end if
--second trial, this will be applied the ips in Failed List only if exists
if the contents of failed is not null then
set d1 to display dialog "do you want to retry with the failed hosts?" buttons {"do it!", "cancel"}
end if
if button returned of d1 is "do it!" then
try
set sftp to do shell script "sftp user@" & failed & Cmd -- put your user name before the @
set end of done1 to contents of return & "-" & failed
on error
set end of failed1 to contents of return & "-" & failed
close sftp
end try
end if
set d2 to display dialog {"Done at: " & done1 & "
Failed at: " & failed1} buttons {"Close"}
if button returned of d2 is "close" then
close
end if
Enjoy!
Model: MBP 2011
AppleScript: 2.2.1
Browser: Safari 534.52.7
Operating System: Mac OS X (10.7)