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 8741019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:14:02+00:00 2026-06-13T11:14:02+00:00

Currently, my script downloads .txt files from an FTP site into a local directory

  • 0

Currently, my script downloads .txt files from an FTP site into a local directory (after checking to see if the directory already contains the file), converts each file into (separate) .csv. I need the data to port into a mysql database.

Here’s the part that I’m having trouble with: running the second part of the script (ballotreader), where rows from the file are imported into SQL, when the path is not dynamic (i.e. R:\path\filename), the script works and the sql table populates. When the path is dynamic, (i.e. ‘R:\path\’+filename) nothing populates. Any suggestions?

for filename in filenames:
    local_filename = os.path.join('R:\\path', filename)
    if os.path.isfile(local_filename) is False:
        print 'New file found.'
        file = open(local_filename, 'wb')
        ftp.retrbinary("RETR " + filename, file.write, 8*1024)
        file.close()
        print 'Downloaded '+filename+' file'
        txt_file = r""+filename
        csv_file = r""+filename+".csv" 
        in_txt = csv.reader(open(txt_file, "rb" ),delimiter = '|')
        outcsv = csv.writer(open(csv_file,'wb'))
        outcsv.writerows(in_txt)

        with open("R:\\path"+csv_file,'rb') as csv_input:
            ballotreader = csv.reader(csv_input, delimiter=',',quotechar ='|') 
            for row in ballotreader:  
                cursor = db.cursor()  
                if row[1] > 0:  
  • 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-06-13T11:14:04+00:00Added an answer on June 13, 2026 at 11:14 am

    The problem is probably with the way you construct path. Try using os.path.join:

    import os
    
    path = os.path.join("R:\\path",csv_file)
    with open(path,'rb') as csv_input:
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently using some configuration files from several project modules inside batch script(scriptx.sh) which
I am writing a script using ftp.exe to download files from an FTP server,
I currently have a script that deletes old log files and then takes any
I currently have a script which allows me to output the list of files
I am currently writing a script which parses the ServiceTage, Computername and Username from
Currently Im have the following script which checks to see if a checkbox value
I maintain a site with a bunch of downloadable files. It is currently hosted
I currently have a very large site approximately 5gb in size with 60,000 files.
I have the following script currently, which gets the category IDs as arrays: $sql_select_categories
I found a nice script to import xml using powershell http://slash4.de/tutorials/Automatic_mediawiki_page_import_powershell_script Currently I don't

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.