skip Trackback error for ftp checking

moonhkt moonhkt at gmail.com
Sat Nov 10 05:51:47 CET 2012


HI All

How to skip Trackback warning/error when input ftp address is not
correct or reject ?

AIX 5.3

from ftplib import FTP
import ftplib
import sys
from optparse import OptionParser

parser = OptionParser()

parser.add_option("-a","--remote_host_address",
dest="remote_host_address",
    help="REMOTE FTP HOST.",metavar="REMOTE FTP HOST")

parser.add_option("-u","--username", dest="username",
    help="USERNAME for ftp sever.",metavar="USERNAME")

parser.add_option("-p","--password", dest="password",
    help="PASSWORD for ftp server.",metavar="PASSWORD")

(options, args ) = parser.parse_args ()

if not (options.remote_host_address):
    parser.error("REMOTE HOST are mandatory")

if options.username and not options.password:
    parser.error("PASSWORD is mandatory if USERNAME is present")

try:
   ftp = FTP(options.remote_host_address)
except ftplib.error_perm,e:
   sys.exit(2)

if options.username:
   try:
      ftp.login(options.username,options.password)
   except ftplib.error_perm,e:
      print "Login failed: %s" % e
      sys.exit(1)
else:
   try:
      ftp.login()
   except ftplib.error_perm,e:
      print "Anonymous login failed: %s" % e
      sys.exit(1)
try:
    print "LOGIN OK"
finally:
    ftp.close()

Command line
-------------------------------
chkftp.py -a teseting

Output as below
----------------------------
Traceback (most recent call last):
  File "...chkftp.py", line 33, in <module>
    ftp = FTP(options.remote_host_address)
  File "/opt/freeware/lib/python2.6/ftplib.py", line 116, in __init__
    self.connect(host)
  File "/opt/freeware/lib/python2.6/ftplib.py", line 131, in connect
    self.sock = socket.create_connection((self.host, self.port),
self.timeout)
  File "/opt/freeware/lib/python2.6/socket.py", line 498, in
create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 2] temporary failure in name resolution.


More information about the Python-list mailing list