简体   繁体   English

uploading.txt 到 FTP 服务器添加新行

[英]uploading .txt to FTP server adds new lines

I'm trying to upload a.txt file to an FTP server using Python and ftplib.我正在尝试使用 Python 和 ftplib 将 a.txt 文件上传到 FTP 服务器。 Connecting works, uploading as well - just a little weird.连接作品,上传作品 - 只是有点奇怪。

My file looks like this:我的文件如下所示:

line1
line2
line3
...

it is created with simple writes file.write('line1\n) ...它是用简单的写入创建的file.write('line1\n) ...

I upload it using storbinary (same with storlines)我使用 storbinary 上传它(与 storlines 相同)

ftp = ftplib.FTP() # and connecting to the server

file = open(file_name, 'rb')
ftp.storbinary('STOR file.txt', file)

Now, when I look at the file in the server (also tried downloading it and then looking at it), it looks like this:现在,当我查看服务器中的文件(也尝试下载它然后查看它)时,它看起来像这样:

line1

line2

line3

...

Why does that happen?为什么会这样? It has to happen while uploading since until then it looks like how it's intended to.它必须在上传时发生,从那时起它看起来就像它的预期那样。

You're creating this file under Windows and sending to a Linux FTP serwer, right?您正在 Windows 下创建此文件并发送到 Linux FTP 服务器,对吗? Windows end lines with \r\n , and Linux with just \n . Windows 以\r\n结束行,而 Linux 仅以\n结束行。 Using storlines instead of storbinary should fix the problem.使用storlines而不是storbinary应该可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM