我正在使用Windows 2008 Server R2上的IIS FTP 7.5和我正在编写的python 2.7.3 ftp模块,遇到非常奇怪的行为。 该模块通过FTP活动模式连接到FTP_TLS库,并将一个简单的文件写入服务器。
我已经安装了带有FTP服务的2008 R2的全新安装,并按照说明生成了自签名证书:
http://www.iis.net/learn/publish/using-the-ftp-service/using-ftp-over-ssl-in-iis-7
http://www.iis.net/learn/publish/using-the-ftp-service/configuring-ftp-firewall-settings-in-iis-7
我能够连接,login,更改目录,列表文件和放置文件没有问题,使用我的Python模块…但是,只要我改变连接到prot_p(encryption数据通道),我无法传输文件。 我从来没有收到从服务器传送的成功响应的226文件,它终于超时。 该文件是在FTP主机上创build的0字节,如果我手动杀死客户端文件消失。
我已经使用强制SSL身份validation和数据传输,在主动模式下在FTP服务器上设置了一个Filezilla服务器,同一个Python模块在放置文件时没有问题。
我已经运行wireshark,但由于它是encryptionstream量最后一次传输过程中写入文件挂起是不可读的,据我所知。
这是我的Python代码:
#!/usr/local/bin/python #imports from ftplib import FTP from ftplib import FTP_TLS import ssl import os import fnmatch import sys import time #connect to FTP host ftp = FTP_TLS() #establish secure channels ftp.auth() # force secure control connection ftp.prot_p() # switch to secure data connection vshost="192.168.1.10" vsport="21" try: ftp.connect(host=vshost,port=vsport) print "Successfully connected to FTPes host " + vshost + " : " + vsport except: print "Unable to connect to FTPes host " + vshost + " : " + vsport exit(1) ftp.set_pasv(0) # FTP Active mode enabled print "FTP Active Mode Enabled" username="test" password="test" try: ftp.login(username,password) print "FTP Login successful" except: print "Unable to login" ftp.quit() exit(1) ftppath="/" try: ftp.cwd(ftppath) except: print "Could not cwd to: " + ftppath ftp.quit() exit(1) try: ftp.pwd() except: print "Could not list current directory" ftp.quit() exit(1) try: f = open('C:\Users\Jeremy\Desktop\test1.txt', 'r') filename="test1.txt" try: ftp.storlines("STOR " + filename, f) f.close() print "Successful Upload!" except: print "Error in uploading the remote file." raise #politely exit the ftp server ftp.quit() print "Ftp has finished uploading all files successfully." exit(0) except: print "Ftp has finished with ERRORS." exit(1)
任何帮助是极大的赞赏。