[英]uploading .txt to FTP server adds new lines
我正在嘗試使用 Python 和 ftplib 將 a.txt 文件上傳到 FTP 服務器。 連接作品,上傳作品 - 只是有點奇怪。
我的文件如下所示:
line1
line2
line3
...
它是用簡單的寫入創建的file.write('line1\n)
...
我使用 storbinary 上傳它(與 storlines 相同)
ftp = ftplib.FTP() # and connecting to the server
file = open(file_name, 'rb')
ftp.storbinary('STOR file.txt', file)
現在,當我查看服務器中的文件(也嘗試下載它然后查看它)時,它看起來像這樣:
line1
line2
line3
...
為什么會這樣? 它必須在上傳時發生,從那時起它看起來就像它的預期那樣。
您正在 Windows 下創建此文件並發送到 Linux FTP 服務器,對嗎? Windows 以\r\n
結束行,而 Linux 僅以\n
結束行。 使用storlines
而不是storbinary
應該可以解決問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.