My code is as per below
import os
import datetime
import time
import sys
import subprocess
import paramiko
import platform
WSDESCRIPTOR = 'ESSImporter'
LOGFILE = 'C:/Logs/%s/%s_%s.log' % (WSDESCRIPTOR.lower(), WSDESCRIPTOR, datetime.datetime.now().strftime("%Y-%m-%d"))
TIBCOSERVER = 'GenevaServer'
TIBCOPORT = '7979'
WEBSERVICEADDRESS = "http://%(server)s:%(port)s/ESSImporter/Services/Interface/intfESSImporter-service.serviceagent/intfwsProcess_ESSImporterEndpoint1" % {'server': TIBCOSERVER, 'port': TIBCOPORT, 'ws': WSDESCRIPTOR}
FILEPATH='/export/home/extracts/out/%s'
REMOTEPATH='C:/ESSSWAP/Ess_Import/%s'
FTPSERVER = 'Server'
FTPUSER = 'test'
if platform.system().upper() == 'WINDOWS' : #dev environment
FTPPASSWORD = "C:/Priv_Key.ppk"
else:
FTPPASSWORD = "/export/Priv_Key.ppk"
#below code is wrong -- I tried a 2D array but since the date will be unknown the this will not work
FILEEXT = 'date is the extension_%s' % (datetime.datetime.now().strftime("%Y-%m-%d"))
FILELIST = (('basket_div_SA.0', 'basket_div_SA'), ('basket_payment_SA.0', 'basket_payment_SA'), ('basket_summary_SA.0', 'basket_summary_SA'), ('basket_swap_SA.0', 'basket_swap_SA'), ('basket_trade_SA.0', 'basket_trade_SA'), ('interest_detail_SA.0', 'interest_detail_SA'), ('unwind_SA.0', 'unwind_SA'))
def getfile(ftphost, fromfile, tofile, tibcoinstanceInfo=None, tibcoinstanceError=None):
if tibcoinstanceInfo:
tibcoinstanceInfo('Connecting to %s as %s with pw %s' % (ftphost, FTPUSER, FTPPASSWORD))
try:
t = paramiko.Transport((ftphost, 22))
key = paramiko.RSAKey.from_private_key_file(FTPPASSWORD)
t.connect(username=FTPUSER, pkey=key)
sftp = paramiko.SFTPClient.from_transport(t)
#in this phase, I need to know which file will be copied so I suppose the code would go here
if sftp != None:
sftp.get(fromfile, tofile)
sftp.close()
if tibcoinstanceInfo:
tibcoinstanceInfo('FTP of the file was successful')
result = True
else:
if tibcoinstanceError:
tibcoinstanceError('Could not connect to the FTP server')
result = False
except Exception, e:
if tibcoinstanceError:
tibcoinstanceError('Error FTPing the file from %s to %s: %s: %s' % (fromfile,tofile,e.__class__, e))
result = False
return result