Home > Backend Development > Python Tutorial > python查看FTP是否能连接成功的方法

python查看FTP是否能连接成功的方法

WBOY
Release: 2016-06-06 11:13:16
Original
2066 people have browsed it

本文实例讲述了python查看FTP是否能连接成功的方法。分享给大家供大家参考。具体如下:

#!/usr/local/bin/python
#-*- coding: UTF-8 -*-
####################################################################
# python 查看FTP是否能连接成功
####################################################################
#import ftplib
##f = ftplib.FTP('192.168.100.214')
##f.login('GDATA_MEM','123456')
##ftplib.set_debuglevel(2) #打开调试级别2,显示详细信息
#data=ftplib.FTP('127.0.0.1','admin','123456')
#print data
from ftplib import FTP
def ftp_open(host='',user='',passwd=''): #打开FTP
  try:
    ftp=FTP()
    ) #打开调试级别2,显示详细信息
    ) #连接
    data=ftp.login(user,passwd) #登录,如果匿名登录则用空串代替即可
    print () #欢迎词
    #print data
    return 1
  except:
    return 0
if __name__=='__main__':
  if ftp_open('127.0.0.1','admin','1234561'): #打开FTP
    print "打开FTP成功"
  else:
    print "打开FTP失败"

Copy after login

希望本文所述对大家的Python程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template