- 论坛徽章:
- 0
|
本帖最后由 zhy19870722 于 2012-07-24 16:02 编辑
- import hashlib
- import os,sys
- import ftplib
- ##md5加密函数
- def md5_decrypt(file_path):
- with open(file_path, 'rb') as f:
- md5_file = hashlib.md5()
- md5_file.update(f.read())
- hash_value = md5_file.hexdigest()
- return hash_value
- def ftp_file_decrypt(ftp_address, file_name):
- ##先连接FTP
- return_hash_value = ""
-
- port = 3030
- timeout = 120
- username = "pcclient"
- password = "pcclient"
- ftp = ftplib.FTP()
- ftp.connect(ftp_address, port, timeout)
- ftp.login(username, password)
- ftp.cwd("/")
- ftp_file_path = "/" + file_name
- file_list = ftp.nlist()
- for file_name in file_list:
- return_hash_value = md5_decrypt(ftp_file_path)
- return return_hash_value
-
复制代码 报错信息如下,为什么会报错ftp没有nlist方法?- Traceback (most recent call last):
- File "C:\Users\Administrator\Desktop\FTP.py", line 47, in <module>
- ftp_hash_val = ftp_file_decrypt(ftp_address, file_name)
- File "C:\Users\Administrator\Desktop\FTP.py", line 34, in ftp_file_decrypt
- file_list = ftp.nlist()
- AttributeError: 'FTP' object has no attribute 'nlist'
复制代码 |
|