1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| import pysftp
def uploadZip(localFile,remoteFile,remoteServerName,remoteUsername,private_key_path):
try:
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
#with pysftp.Connection(host=remoteServerName, username=remoteUsername, private_key=private_key_path, cnopts=cnopts) as sftp:
with pysftp.Connection(host=remoteServerName, username=remoteUsername, private_key=private_key_path, cnopts=cnopts) as sftp:
sftp.put(localFile,remoteFile)
except Exception, e:
print('Echec du transfert du fichier "{}" sur "{}"'.format(localFile,remoteServerName))
print('Erreur : {}'.format(e))
localFile = r'C:\Users\test.arcgis\Desktop\info sftp.txt'
remoteFile = '/depot/transfert/arcgis/integration/test.txt'
remoteServerName = 'xxx.xxx.xxx.xxx'
remoteUserName = 'user'
private_key_path = r'chemin\vers\cle\privee.ppk'
uploadZip(localFile,remoteFile,remoteServerName,remoteUserName,private_key_path) |
Partager