python / python/cpython

ftplib storbinary

未关闭
#124,850 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

type-bug
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

Bug report

Bug description:

There's a problem with SSL and the storbinary method. I get this error:

Error uploading yourfile.mp3: [SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:2685)

A YouTuber posted a fix which creates your own storbinary function and eliminates some code in the original that solves the problem. I attached the fix below. You use this function in place of the method that comes with the library.

def storbinary(self, cmd, fp, blocksize=8192, callback=None, rest=None):
    self.voidcmd('TYPE I')
    with self.transfercmd(cmd, rest) as conn:
        while 1:
            buf = fp.read(blocksize)
            if not buf: break
            conn.sendall(buf)
            if callback: callback(buf)
    return self.voidresp()
    
    ----
    ftps = FTP_TLS()
    ftps.set_pasv(True)

      ....
    for upload in uploads:
        print(upload)
        with open(upload, 'rb') as file:  # Use 'with' to ensure the file is closed properly
            remote_filename = os.path.basename(upload)  # Get the base filename for uploading
            try:
                storbinary(ftps, f'STOR {remote_filename}', file)
            #    ftps.storbinary(f'STOR {remote_filename}', file) 

                print(f'Successfully uploaded: {remote_filename}')
            except all_errors as e:
                print(f'Error uploading {remote_filename}: {e}')
    # Connect to the server
    ftps.connect(ftps_host)
    ftps.login(user=ftps_user, passwd=ftps_password)
    ftps.prot_p()  # Switch to secure data connection

    
CPython versions tested on:

3.12

Operating systems tested on:

macOS

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 ftplib.FTP_TLS.storbinary 开始,复现针对 macOS 上 Python 3.12 所描述的 SSL 上传失败,并将其与随附的替代函数进行比较。未指定 repository 文件或测试;完成的标准是,在不替换 storbinary 的情况下,所报告的上传能够正常工作,并且该行为有回归覆盖。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
networking
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。