# Extract NMUK Interface Files from Stonebranch Server

import ftplib
import os

# Get Current Path
dir_path = os.path.dirname(os.path.realpath(__file__))

def main():
# set-up ftp connection to iSeries 
#	ftp = ftplib.FTP('172.16.1.3')
    ftp = ftplib.FTP('10.2.2.101')
    ftp.login('ftpuwms','V6qDQhpB')
    ftp.cwd('/kcc6/633/interface/WMS/common/komoutput')
    filenames = ftp.nlst('RECONC')
#loop through list of interface files
    file_path = os.path.join('f:/kukfiles/adhoc')
    for filename in filenames:
        host_file = os.path.join(file_path, filename)
        try:
            with open(host_file, 'wb') as local_file:
                ftp.retrbinary('RETR ' + filename, local_file.write)
#                ftp.delete(filename)
        except ftplib.error_perm:
            pass 
    filenames = ftp.nlst('PICKPLAN')
#loop through list of interface files
    file_path = os.path.join('f:/kukfiles/adhoc')
    for filename in filenames:
        host_file = os.path.join(file_path, filename)
        try:
            with open(host_file, 'wb') as local_file:
                ftp.retrbinary('RETR ' + filename, local_file.write)
#                ftp.delete(filename)
        except ftplib.error_perm:
            pass
    ftp.quit()
    ftp = ftplib.FTP('10.108.208.194')
    ftp.login('phplogon','logon')
    ftp.cwd('/kukvims')
    filenames = ftp.nlst('FINVNTP')
#loop through list of interface files
    file_path = os.path.join('f:/kukfiles/adhoc')
    for filename in filenames:
        host_file = os.path.join(file_path, filename)
        try:
            with open(host_file, 'wb') as local_file:
                ftp.retrbinary('RETR ' + filename, local_file.write)
#                ftp.delete(filename)
        except ftplib.error_perm:
            pass        
    ftp.quit()
    
	
if __name__ == '__main__':
    main()