简体   繁体   中英

uploading .txt to FTP server adds new lines

I'm trying to upload a.txt file to an FTP server using Python and ftplib. 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) ...

I upload it using storbinary (same with 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 end lines with \r\n , and Linux with just \n . Using storlines instead of storbinary should fix the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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