AppleScript C Perl Shell Xcode Other

FTP Login procedure for FTP AppleScripts to use

Post Reply
coding / applescript     Views: 2500Prev .. Next
FTP Login procedure for FTP AppleScripts to usePosted: Sunday, June 20, 2010 [21:18:24] - 1
rootPosted by:rootMember Since:
June 16 2010
Posts: 357
This is a Login procedure that could be referenced from any AppleScript to connect to your server without saving login credentials in open script.
View Codeon doLogin()
tell application "System Events"
if not (exists process "Terminal") then
set aDone to 0
set wCounter to 0
tell application "Terminal"
activate
delay 2
make new document
end tell
else
delay 5
set wCounter to 1
tell application "Terminal"
activate
delay 2
make new document
end tell
end if
end tell

if wCounter < 1 then
set doneU to "no terminal"
-- report to external program to quit terminal afterwards
do shell script "echo " & quoted form of doneU & " > /closeterminal.txt"
end if

delay 10

tell application "System Events"
tell process "Terminal"
keystroke "n" using {command down}
delay 3
keystroke "k" using {command down}
delay 1
keystroke "ftp"
delay 2
keystroke return
delay 5
keystroke "k" using {command down}
delay 1
keystroke "a" using {command down}
delay 1
keystroke "c" using {command down}
delay 1
set screenData to (the clipboard) as text
if screenData does not contain "ftp" then
delay 5
keystroke "n" using {command down}
delay 5
keystroke "ftp"
delay 3
keystroke return
delay 5
end if
delay 3

keystroke "open IP_or_URI"
delay 1
keystroke return
delay 10
keystroke "UserName"
delay 1
keystroke return
delay 2
keystroke "Password"
delay 1
keystroke return
delay 4

keystroke "a" using {command down}
delay 1
keystroke "c" using {command down}
delay 1
set screenLogged to (the clipboard) as text
-- UserName must match UserName above
if screenLogged contains "230 User UserName logged in" then
return true
else
-- this is reporting procedure (optional)
do shell script ("echo " & quoted form of screenLogged & " | perl /error.terminal.login.cgi")
-- this is reporting procedure end (optional)
set screenLogged to ""
return false
end if
end tell
end tell
delay 2
end doLogin


Save this AppleScript as an .app and make reference to it in any AppleScript as:
View Code-- set full path to the script above
set p to "/ftp.login.app"
set otherScript to POSIX file p as alias
set myScript to load script otherScript
set myResult to myScript's doLogin()
delay 2
-- run only if reported logged to the server
if myResult is true then
tell application "System Events"
tell process "Terminal"
-- do your FTP routine here...
end tell
end tell
end if
-- end if myResult is true


You can create login programs for each server with appropriate credentials.There's no place like ~
coding / applescriptPrev .. Next
 
Post Reply
Home - Coding: AppleScript C Perl Shell Xcode Other
Our Telegram Group