Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7667747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:11:01+00:00 2026-05-31T15:11:01+00:00

Hi I am trying to create an FTP server and to aid the development

  • 0

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.

I wrote my own handler in pyftpdlib after this tutorial: http://code.google.com/p/pyftpdlib/wiki/Tutorial#3.8_-_Event_callbacks

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.

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):

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

The full source:
http://pastie.org/3552079

Source of the config-file:
http://pastie.org/3552085

EDIT-> (and of course the error):

[root]@85.230.122.159:40659 unhandled exception in instance <pyftpdlib.ftpserver.DTPHandler object at 0xb75f49ec>
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'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:11:03+00:00Added an answer on May 31, 2026 at 3:11 pm

    The problem in this case was that by reading the file it left the file open.

    I changed to this and it’s working much better:

    config = ConfigParser.RawConfigParser()
        fp = open('config.cfg')
            config.readfp(fp)
    

    And then when I’m finished reading in the constructor I add:

    #Close the file
    fp.close()
    

    And voila, you can open how many objects of the class you want and it won’t show any errors. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using C# to upload some file to a ftp server. If the
I'm trying to send a file using ftp. I have the following code: string
I am trying to copy file(s) using webrequest inside WCF. I need some suggestions.
I am trying to create a ftp server in c#. This server should listen
I am trying to download file using FTP, and in between if connection terminates
I am trying to create a ftp client with uploading a file capability. But
I am trying to download files from an ftp server using C# and ftpwebrequest.
I am trying to automate some upload/download tasks from an ftp web server. When
I'm trying to upload large file (>100Mb) using Apache commons-net FTP library to Secure
I am trying to upload a file via ftp using FtpWebRequest as below: ftpRequest

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.