Python: Check whether the FTP connection is successful. python: Check the ftp connection.
This example describes how to check whether FTP connection is successful in python. 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.