python / python/cpython

ftplib storbinary

未關閉
#124,850 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

type-bug
主要語言
Python
星號
77.2k
分支
36k
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 摘要。