Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does my code raise an exception?
    primarykey
    data
    text
    <p>Hi I am trying to create an FTP server and to aid the development I'm using pyftpdlib. What I wanted to do is to do some file operations if a user downloads a specific file but sometimes it raises an exception and I don't really know why.</p> <p>I wrote my own handler in pyftpdlib after this tutorial: <a href="http://code.google.com/p/pyftpdlib/wiki/Tutorial#3.8_-_Event_callbacks" rel="nofollow">http://code.google.com/p/pyftpdlib/wiki/Tutorial#3.8_-_Event_callbacks</a></p> <p>But something goes terribly wrong sometimes when the user downloads the log file (which I intend to do some file operations on) and I don't really understand why. I have another class which basically reads from a configuration file and the error message said it couldn't find FTP Section. But it's strange because I clearly have it in my configuration file and it is working sometimes perfectly.</p> <p>May this error appear because I have two "Connection" objects? That's the only guess I have, so I would be very glad if someone could explain what's going wrong. Here is my code that's troubled (nevermind the file.name check because that was very recently added):</p> <pre><code>class ArchiveHandler(ftpserver.FTPHandler): def on_login(self, username): # do something when user login pass def on_logout(self, username): # do something when user logs out pass def on_file_sent(self, file): "What to do when retrieved the file the class is watching over" attr = Connection() if attr.getarchive() == 'true': t = datetime.now() if file.name == "log.log": try: shutil.copy2(file, attr.getdir() + ".archive/" + str(t.strftime("%Y-%m-%d_%H:%M:%S") + '.log')) except OSError: print 'Could not copy file' raise if attr.getremain() == 'false': try: os.remove(file) except OSError: print 'Could not remove file' raise </code></pre> <p>The full source: <a href="http://pastie.org/3552079" rel="nofollow">http://pastie.org/3552079</a></p> <p>Source of the config-file: <a href="http://pastie.org/3552085" rel="nofollow">http://pastie.org/3552085</a></p> <p>EDIT-> (and of course the error):</p> <pre><code>[root]@85.230.122.159:40659 unhandled exception in instance &lt;pyftpdlib.ftpserver.DTPHandler object at 0xb75f49ec&gt; Traceback (most recent call last): File "/usr/lib/python2.6/asyncore.py", line 84, in write obj.handle_write_event() File "/usr/lib/python2.6/asyncore.py", line 435, in handle_write_event self.handle_write() File "/usr/lib/python2.6/asynchat.py", line 174, in handle_write self.initiate_send() File "/usr/lib/python2.6/asynchat.py", line 215, in initiate_send self.handle_close() File "/usr/local/lib/python2.6/dist-packages/pyftpdlib/ftpserver.py", line 1232, in handle_close self.close() File "/usr/local/lib/python2.6/dist-packages/pyftpdlib/ftpserver.py", line 1261, in close self.cmd_channel.on_file_sent(filename) File "ftp.py", line 87, in on_file_sent File "ftp.py", line 12, in __init__ File "/usr/lib/python2.6/ConfigParser.py", line 311, in get raise NoSectionError(section) NoSectionError: No section: 'FTP Section' </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload