I can&#39;t seem to figure out how a client uploads a file to the server using twisted.protocols.ftp. For the server side I am using the ftpserver example from the twisted website. For the client I have the following:<br><br>
from twisted.protocols.ftp import FTPClient, FTPFileListProtocol<br>from twisted.internet.protocol import Protocol, ClientCreator<br>from twisted.python import usage<br>from twisted.internet import reactor<br><br>from twisted.protocols.basic import FileSender<br>
<br><br># Standard library imports<br>import string<br>import sys<br>try:<br>    from cStringIO import StringIO<br>except ImportError:<br>    from StringIO import StringIO<br><br><br>class BufferingProtocol(Protocol):<br>
    &quot;&quot;&quot;Simple utility class that holds all data written to it in a buffer.&quot;&quot;&quot;<br>    def __init__(self, fileToWrite):<br>        self.buffer = StringIO()<br>        self.fileToWrite = fileToWrite<br>
<br>    def dataReceived(self, data):<br>        self.buffer.write(data)<br><br># Define some callbacks<br><br>def success(response):<br>    print &#39;Success!  Got response:&#39;<br>    print &#39;---&#39;<br>    if response is None:<br>
        print None<br>    else:<br>        print string.join(response, &#39;\n&#39;)<br>    print &#39;---&#39;<br><br><br>def fail(error):<br>    print &#39;Failed.  Error was:&#39;<br>    print error<br><br>def showFiles(result, fileListProtocol):<br>
    print &#39;Processed file listing:&#39;<br>    for file in fileListProtocol.files:<br>        print &#39;    %s: %d bytes, %s&#39; \<br>              % (file[&#39;filename&#39;], file[&#39;size&#39;], file[&#39;date&#39;])<br>
    print &#39;Total: %d files&#39; % (len(fileListProtocol.files))<br><br>def showBuffer(result, bufferProtocol):<br>    print &#39;Got data:&#39;<br>    print bufferProtocol.buffer.getvalue()<br><br>def writeBufferToFile(result, bufferProtocol):<br>
    f = open(bufferProtocol.fileToWrite, &#39;w&#39;)<br>    f.write(bufferProtocol.buffer.getvalue())<br>    f.close()<br><br><br>class Options(usage.Options):<br>    optParameters = [[&#39;host&#39;, &#39;h&#39;, &#39;localhost&#39;],<br>
                     [&#39;port&#39;, &#39;p&#39;, 21],<br>                     [&#39;username&#39;, &#39;u&#39;, &#39;anonymous&#39;],<br>                     [&#39;password&#39;, None, &#39;bozo&#39;],<br>                     [&#39;passive&#39;, None, 0],<br>
                     [&#39;debug&#39;, &#39;d&#39;, 1],<br>                    ]<br><br>def run():<br>    # Get config<br>    config = Options()<br>    config.parseOptions()<br>    config.opts[&#39;port&#39;] = int(config.opts[&#39;port&#39;])<br>
    config.opts[&#39;passive&#39;] = int(config.opts[&#39;passive&#39;])<br>    config.opts[&#39;debug&#39;] = int(config.opts[&#39;debug&#39;])<br>    <br>    # Create the client<br>    FTPClient.debug = config.opts[&#39;debug&#39;]<br>
    creator = ClientCreator(reactor, FTPClient, config.opts[&#39;username&#39;],<br>                            config.opts[&#39;password&#39;], passive=config.opts[&#39;passive&#39;])<br>    creator.connectTCP(config.opts[&#39;host&#39;], config.opts[&#39;port&#39;]).addCallback(connectionMade).addErrback(connectionFailed)<br>
    reactor.run()<br><br>def connectionFailed(f):<br>    print &quot;Connection Failed:&quot;, f<br>    reactor.stop()<br><br>def fileTransferFail(failure):<br>    failure.printTraceback()<br>    reactor.stop()<br> <br>def cbStore(consumer, filename):<br>
    fs = FileSender()<br>    d = fs.beginFileTransfer(open(filename, &#39;r&#39;), consumer)<br>    d.addCallback(lambda _: consumer.finish()).addErrback(fileTransferFail)<br>    return d<br><br><br>def connectionMade(ftpClient):<br>
    # Get the current working directory<br>    ftpClient.pwd().addCallbacks(success, fail)<br><br>    # Get a detailed listing of the current directory<br>    fileList = FTPFileListProtocol()<br>    d = ftpClient.list(&#39;.&#39;, fileList)<br>
    d.addCallbacks(showFiles, fail, callbackArgs=(fileList,))<br><br>    # Change to the parent directory<br>    ftpClient.cdup().addCallbacks(success, fail) <br><br>    filename = &quot;FtpDownload.txt&quot;<br>    uploadpath = &quot;FtpUpload.txt&quot;<br>
    d1, d2 = ftpClient.storeFile(uploadpath)<br>    d1.addCallback(cbStore, filename).addErrback(fileTransferFail)<br>    d2.addCallback(lambda _: reactor.stop())<br><br><br># this only runs if the module was *not* imported<br>
if __name__ == &#39;__main__&#39;:<br>    run()<br><br>When I run this, it returns “Failure: twisted.protocols.ftp.CommandFailed: [&#39;550 FtpUpload.txt: Permission denied&#39;]”. I can download a file, and view the files in a folder, I just can&#39;t upload a file. Also if I log-in as one the users in the .dat file, instead of anonymous, I can&#39;t even view the files in a folder. So is there a way to give anonymous or a user in the .dat file more permissions, like the write permission?<br>
<div style="visibility: hidden; display: inline;" id="avg_ls_inline_popup"></div><style type="text/css">#avg_ls_inline_popup {  position:absolute;  z-index:9999;  padding: 0px 0px;  margin-left: 0px;  margin-top: 0px;  width: 240px;  overflow: hidden;  word-wrap: break-word;  color: black;  font-size: 10px;  text-align: left;  line-height: 13px;}</style>