I want to write a Python script that connects to the remote SFTP server and creates a ZIP file in the remote server which consists of specific files present in remote server itself. I have written the below script, I m using pysftp for this,
with pysftp.Connection(host=myHostname, username=myUsername, password=myPassword, cnopts=cnopts) as sftp:
print("Connection succesfully stablished ... ")
files = ['user/1.csv','user/2.csv','user/test.csv', 'user/test1.csv']
with zipfile.ZipFile('zipfile.zip', 'w') as zipMe:
for file in files:
zipMe.write(file, file.split('/')[-1], compress_type=zipfile.ZIP_DEFLATED)
But instead of creating a ZIP file in the remote server, an ZIP file gets created in the local. Can anyone please help me with this?