I have created a macro that does the following:
- Reads in data and saves it to a csv at a specified location so it can be read by the next steps
- Reads in a .pem private key file from a specified location on the users computer and connects to an sftp using this
- Uploads a file to the sftp
The python for this is as follows. It works in designer but I'm having issues in porting it to the gallery to be scheduled.
from ayx import Package
import pysftp as pysftp
import pandas as pd
from ayx import Alteryx
data = Alteryx.read("#1")
data.to_csv( 'LOCAL_LOCATION' , encoding = 'utf-8', index = False)
def sftpPush():
try:
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
sftp = pysftp.Connection(host="HOSTNAME", username="USERNAME", private_key="PRIVATEKEY_LOCATION", port='PORT', cnopts=cnopts)
sftp.put('LOCAL_LOCATION', 'LOCATION_ON_SFTP')
sftp.close()
# hostname, username and port are usually filled in but have been removed for security here.
#The rest is provided by macro inputs
except Exception as e:
print(e)
sftpPush()My problems are:
- The .pem private key file is not being picked up a workflow dependency, and as it sits on users' local PCs, it is not accessible from the gallery. Is there a way to package it in with the workflow?
- Ideally, I wouldn't want to save datasets locally before uploading them to the sftp - this isn't that important but it would be nice.
Thanks in advance for your help!