This article mainly introduces how to check whether FTP can be connected successfully using python. The example analyzes the skills related to FTP connection using Python, which has some reference value, for more information about how to check whether FTP connection is successful, see the example in this article. Share it with you for your reference. The details are as follows:
#! /Usr/local/bin/python #-*-coding: UTF-8 -*-#################################### ################################# check whether the FTP connection is successful in python ######################################## ############################ import ftplib ## f = ftplib. FTP ('2017. 168.100.214 ') # f. login ('gdata _ MEM ', '000000') # ftplib. set_debuglevel (2) # enable debug level 2 and display details # data = ftplib. FTP ('2017. 0.0.1 ', 'admin', '000000') # print datafrom ftplib import FTPdef ftp_open (host = '', user ='', passwd = ''): # Open FTP try: ftp = FTP () # enable debugging level 2 and display details) # connect to data = ftp. login (user, passwd) # log on. if you log on anonymously, use an empty string instead of print () # Welcome word # print data return 1 failed t: return 0if _ name __= = '_ main _': if ftp_open ('2017. 0.0.1 ', 'admin', '000000'): # enable FTP print "FTP opened successfully" else: print "FTP opened failed"
I hope this article will help you with Python programming.