#print "Enter the server name \n"
server = "x.x.x.x"
#ftp = ftplib.FTP(server)
#print "Enter the USN /PWD"
path = raw_input ("Enter the path \n")
ftp = ftplib.FTP(server,'xxx','yyy')
ftp.cwd(path)
fname = raw_input("Enter the Fname \n")
with open(fname) as file_to_check:
#read content of the file
csv1 = file_to_check.read()
#pipe the contents of the file through
md5_original = hashlib.md5(csv1).hexdigest()
localfile = open(fname, 'wb')
ftp.retrbinary('RETR ' + fname, localfile.write, 512)
print "Done ...."
ftp.quit()
curpath = os.getcwd()
os.chdir(curdir)
with open(localfile) as file_to_check:
#read content of the file
csv2 = file_to_check.read()
#pipe the contents of the file through
md5_download = hashlib.md5(csv2).hexdigest()
# Finally compare original MD5 with freshly calculated
if orginal_md5 == md5_returned:
print "MD5 verified."
else:
print "MD5 verification failed!."
当我运行这个程序时,\我在 ftp.retrbinary('RETR' + fname, localfile.write, 1024) 行出现以下错误
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\ftplib.py", line 401, in retrbinary
data = conn.recv(blocksize)
socket.error: [Errno 10054] An existing connection was forcibly closed by the remote host
我不知道出了什么问题。请帮我解决