python ftp连接timeout 421

找半天没找到好的方法,要么用个线程写个timeout心跳?看其他人说心跳不管用
由于ftp连接本身的超时时间就已经挺大了,所以超时后再重新连接吧

try:
        remote_ftp.storbinary("STOR " + filename,file_handle,buf_size)
        print '*** Uploaded "%s" to CWD' % fname
    except:		#这个地方我也不知道catch什么参数,用ftplib.error_perm进不去,只好先看所有的异常了
        print "ftp time out reconnect!"
        try:
            connect_ftp_report(get_report_ip(),21,get_report_path(),get_report_user(),get_report_passwd())
            remote_ftp.storbinary("STOR " + filename,file_handle,buf_size)
            print '*** Uploaded "%s" to CWD' % fname
        except ftplib.error_perm:
            print "reconnect ftp error!"
            return

猜你喜欢

转载自blog.csdn.net/weixin_42651205/article/details/84653012
421