[Twisted-Python] ftpClient.py, retrieveFile, and line ending issues
Hello, If any of you have a spare minute, I can't figure out else where I might solve my present dilemma. Its certainly likely that my only issues are ignorance about Python's file operations or the features that are a part of other FTP clients that I use. I'm using the ftpclient.py code to write a script which downloads file via FTP. My example code shows the basics. The file is transferred, but the lines seem to have different line endings when I view them 'hexlified' in xemacs. My twisted-created files has hex 0D0D 0D0D 0D0D at the end of lines while a file downloaded using SmartFTP has hex 0D0A 0D0A. Is it clear, based on that information, if there is an issue in my code? Or an easy way to fix it? class FileWriterProtocol(Protocol): def __init__(self, filename): self.file = open(filename, 'w') def dataReceived(self, data): self.file.write(data) def connectionMade(ftpClient): proto2 = FileWriterProtocol( 'c:/ftpfile1.txt' ) # Get the file, and quit when done d = ftpClient.retrieveFile( 's1/s2/T2005C.processed' , proto2) d.addCallback(lambda result: reactor.stop()) Thanks very much, Keith Gunderson
On Tue, 2005-12-06 at 16:41 -0600, Keith.Gunderson@act.org wrote:
class FileWriterProtocol(Protocol): def __init__(self, filename): self.file = open(filename, 'w')
You probably want open(filename, "wb"), which implies binary mode. On Unix this does nothing, on Windows it keeps Windows from screwing with your data line endings.
Itamar Shtull-Trauring <itamar@itamarst.org> writes:
On Tue, 2005-12-06 at 16:41 -0600, Keith.Gunderson@act.org wrote:
class FileWriterProtocol(Protocol): def __init__(self, filename): self.file = open(filename, 'w')
You probably want open(filename, "wb"), which implies binary mode. On Unix this does nothing,
Actually, this is not quite true!
import array open('foo', 'w').write(array.array('b', [0])) Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: argument 1 must be string or read-only character buffer, not array.array open('foo', 'wb').write(array.array('b', [0]))
on Windows it keeps Windows from screwing with your data line endings.
This is still true. pedantically-ly y'rs mwh -- If you're talking "useful", I'm not your bot. -- Tim Peters, 08 Nov 2001
On Wed, 2005-12-07 at 09:41 +0000, Michael Hudson wrote:
import array open('foo', 'w').write(array.array('b', [0])) Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: argument 1 must be string or read-only character buffer, not array.array open('foo', 'wb').write(array.array('b', [0]))
OK then, "wb" does nothing on Unix modulo Python doing wacky shit ;)
participants (3)
-
Itamar Shtull-Trauring
-
Keith.Gunderson@act.org
-
Michael Hudson