I use curl to ftp PDFs to a network printer. Occasionally the printer rip crashes or the ftp services stop. This causes problems with my workflow and so I would like a way to check the connection, before the script attempts to upload the files, maybe just a simple login and then disconnect. If there’s a connection problem then I can instruct my script to ftp to another printer.
set isReachable to (do shell script "/full/path/to/reachable [url=ftp://ftp.thePrinter.local]ftp.thePrinter.local[/url]") as boolean
the CLI uses the Reachability API of the SystemConfiguration framework.
The argument can be an URL or a bonjour host name. IPv4 Addresses might not work
It can take a few seconds to return the result (true or false).
Many thanks for your reply and apologies for taking so long to reply.
I have been testing this morning and the reachable CLI is always returning true when I know the server is down/rebooting!
I logged onto the printer and rebooted the server, then I simultaneously ran the below script and kept refreshing a cyberduck connection to the server. Each time I ran the script it returned true but when I refreshed the Cyberduck connection it failed until the server had rebooted.
set isReachable to (do shell script "reachable ftp://anonymous@126.0.17.132/") as boolean
I put the binary in /usr/bin
Any ideas why this would still be returning true when the server is down?
just checked the printer settings and it does have a name, but do you mean a dns name or a name entered for the printer in my hosts file or some other name associated with printer?
after a bit more searching and testing I came up with this:
set ftpStatus to true
try
set curlResponse to do shell script "curl --connect-timeout 5 ftp://126.0.17.131"
on error theError
set ftpStatus to false
end try
Many thanks again for your time Stefan & McUsrII,
Nik
# works with both http and ftp protocols,
# that is, names and IP's
hostUP for "http://macscripter.net"
on hostUP for anAddress
set hostStatus to true
try
set curlResponse to do shell script "curl --connect-timeout 5 " & anAddress
on error theError
set hostStatus to false
end try
return hostStatus
end hostUP
I’ve also created a handler, because it’s running on a remote machine I got the script to email me when one of the printers is down:
set printerIP to my checkPrinterFtpStatus()
on checkPrinterFtpStatus()
try
do shell script "curl --connect-timeout 5 ftp://126.0.17.131"
set printerIP to "126.0.17.131"
on error theError
my printerFtpError("Fiery1")
try
do shell script "curl --connect-timeout 5 ftp://126.0.17.132"
set printerIP to "126.0.17.132"
on error theError
my printerFtpError("Fiery2")
set printerIP to "dead"
end try
end try
return printerIP
end checkPrinterFtpStatus
on printerFtpError(Fiery)
try
set messTo to "macadmin@myemail.co.uk"
set messSub to Fiery & " ftp services have stopped running!"
set messBody to Fiery & " ftp services have stopped running!" & return & "Please reboot the " & Fiery & " server."
do shell script "echo " & (quoted form of messBody) & " | mail -s " & (quoted form of messSub) & space & messTo & space & " -f Fast_Track_Proofing2"
on error
display dialog theError giving up after 10
error number -128
end try
end printerFtpError