Using Python 3.6 successfully retrieving data from mssqlserver and querying oracle for historical data and exporting it via Pandas to a tab delimited file which I then want to be able to ftp to another mssql server location. Since I have not tried this before, I experimented as follows:
\\\\\\\\\\\\\\\\\\\ This works: passing hardcoded variable \\\\\\\\\\\\\\\\\\\\
from ftplib import FTP
host='myserver'
host_name='group_user_name'
host_pw='hostpassword'
host_dir='myworkingdirectory'
ftp = FTP(host)
ftp.login(user=host_name, passwd =host_pw)
ftp.cwd(host_dir)
filename = 'c:/temp/cigfun.txt'
fn = 'cigfun.txt'
def placeFile():
ftp.storbinary('STOR '+fn, open(filename, 'rb'))
ftp.quit()
placeFile()
\\\\\\\\\\\\\\ This also works: hard coded \\\\\\\\\\\\\\
from ftplib import FTP
ftp = FTP('myserver')
ftp.login(user='group_user_name', passwd ='hostpassword')
ftp.cwd('myworkingdirectory')
ftp.retrlines('LIST')
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
This does not connect: retrieving data from stored procedure in MSSQL
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
if sql_id == str(5):
sql_cursor.execute("[dbo].[usp_GetProcess_"+seq_action+"] @sql_id = "+ sql_id)
table = sql_cursor.fetchall()
for row in table:
host = "'"+row[1]+"'"
host_name = "'"+row[2]+"'"
host_pw = "'"+row[3]+"'"
host_dir = "'"+row[4]+"'"
host_dir = re.sub('[cd ]', '', host_dir)
ftp_file = row[9]
f_type = row[10]
if f_type == "Tab (txt)":
f_type = '.txt'
elif f_type == "Comma (csv)":
f_type = '.csv'
else: f_type = '.xlsx'
path_file = "'"+ftp_file + f_type+"'"
fn="'"+os.path.basename(path_file)
path_file = path_file.replace(r'\\','/')
from ftplib import FTP
ftp = FTP(host)
ftp.login(user = host_name, passwd = host_pw)
ftp.cwd(host_dir)
\\\\\\\\\\\\\\ throws the following error:
File "C:\Users\A22021\AppData\Local\Continuum\anaconda332\lib\socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
gaierror: [Errno 11004] getaddrinfo failed
aside from my awkward efforts at coding (only my 3rd production attempt using Python), can you see anything obvious that would cause the failure? error messages are so cryptic. I suspect it might have something to do with coded variable assignments, but I am baffled right now. Any constructive advice appreciated. PLG