################################# # List all non-standard packages to be imported by your # script here (only missing packages will be installed) from ayx import Package Package.installPackages(['pandas','pysftp']) from ayx import Alteryx import pysftp as pysftp import pandas as pd #User PEM File path pemKey = Alteryx.read("#3") pemKeyStr = pemKey.iloc[0]['Key'] #User sFTP Host path ftpHost = Alteryx.read("#4") ftpHostStr = ftpHost.iloc[0]['sFTP_Host'] #User sFTP Username ftpUsername = Alteryx.read("#5") ftpUsernameStr = ftpUsername.iloc[0]['sFTP_Username'] cnopts = pysftp.CnOpts() cnopts.hostkeys = None srv = pysftp.Connection(host=ftpHostStr, username=ftpUsernameStr, private_key=pemKeyStr, cnopts=cnopts) ftpDir = Alteryx.read("#1") ftpDirStr = ftpDir.iloc[0]['sFTP_Directory'] #"/test/" # Get the directory and file listing data = srv.listdir(ftpDirStr) # Closes the connection srv.close() # Prints out the directories and files, line by line - testing only #for i in data: # print (i) df_cols = ['sFTP_Path'] rows = [] for i in data: #localPath = localPath + '\\' + str(i) rows.append({'sFTP_Path':ftpDirStr + '/' + i}) #print(rows) out_df = pd.DataFrame(rows, columns = df_cols) #print(df) Alteryx.write(out_df,1) #################################