Hi,
I'm trying to read IP and login info from a text file params.txt. The contents of the text file are:
IP = '1.2.3.4'
UID = 'anonymous'
PWD = 'my@my.com'
Upload Directory = '/'
Home Directory = 'C:/Users/MyDocuments/Python/FilesUpload/'

Can someone help me please?

import ftplib
import re
import os
import sys
import traceback  

param = open("params.txt", "r")
    for line in param:
        if re.match("(.*)IP(.*)", line):
            print ("" + re.sub('IP = ','',line))
            FtpIP = re.sub('IP = ','',line)
            print ("FTPIP = " + FtpIP)

ftp = ftplib.FTP()
print ("" + FtpIP)
ftp.connect(FtpIP)

File "C:\Python32\lib\socket.py", line 386, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 11004] getaddrinfo failed

lines 8-12 are misindented, quotes are not allowed in IP addresses (FtpIP is also against the Python naming convention suggesting it is class, not variable):

import ftplib
import re

with open("params.txt", "r") as param:
    for line in param:
        if re.match("(.*)IP(.*)", line):
            print ("" + re.sub('IP = ','',line))
            FtpIP = re.sub('IP = ','',line).strip("' \n")
            print ("FTPIP = " + repr(FtpIP))

ftp = ftplib.FTP()
print(FtpIP) # no quotes
ftp.connect(FtpIP)

I made the changes but it still is not working. Now getting

socket.error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

Can simplify code to this.

import re
from ftplib import FTP

with open('params.txt.txt') as f:
    ip = re.search(r"IP.*'(.*)'", f.read()).group(1)

ftp = FTP(ip)
ftp.login()

I made the changes but it still is not working. Now getting

Can be something like port,firewall problem or Active and Passive mode.
http://stackoverflow.com/questions/3451817/python-ftplib-timing-out

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.