Question

I wrote a function append_line() in ftplib (based on storelines()):

def append_line(self, cmd, string):
    self.voidcmd('TYPE A')
    conn = self.transfercmd(cmd)
    conn.sendall(string)
    conn.close()

    return self.voidresp()

When I call:

ftp.append_line("APPE " + "Text.dat", "This is my string\n\n")

it will append the string to the mentioned file, but ignores the newline. So, socket.sendall is ignoring the character \n.

How can I properly update the file with a newline character?

Was it helpful?

Solution

It looks like you have a different problem. When I try to sendall with your string, it appears to work:

Client code:

    from socket import *
    s=socket(AF_INET, SOCK_STREAM)
    s.connect(("localhost", 6789))
    string = "This is my string\n\nAFTER_IT"
    s.sendall(string)

Server code:

    from socket import *
    s=socket(AF_INET, SOCK_STREAM)
    s.bind(("", 6789))
    s.listen(8)
    (c, a) = s.accept()
    data=c.recv(1000)
    data # Displays 'This is my string\n\nAFTER_IT'

OTHER TIPS

You may want to try sending "\r\n\r\n" instead of "\n\n".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top