mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
Don't close paramiko SFTP multiple times in the same runner pass. Noticeable performance increase.
This commit is contained in:
@@ -135,29 +135,29 @@ class Connection(object):
|
||||
if not os.path.exists(in_path):
|
||||
raise errors.AnsibleFileNotFound("file or module does not exist: %s" % in_path)
|
||||
try:
|
||||
sftp = self.ssh.open_sftp()
|
||||
self.sftp = self.ssh.open_sftp()
|
||||
except:
|
||||
raise errors.AnsibleError("failed to open a SFTP connection")
|
||||
try:
|
||||
sftp.put(in_path, out_path)
|
||||
self.sftp.put(in_path, out_path)
|
||||
except IOError:
|
||||
raise errors.AnsibleError("failed to transfer file to %s" % out_path)
|
||||
sftp.close()
|
||||
|
||||
def fetch_file(self, in_path, out_path):
|
||||
''' save a remote file to the specified path '''
|
||||
vvv("FETCH %s TO %s" % (in_path, out_path), host=self.host)
|
||||
try:
|
||||
sftp = self.ssh.open_sftp()
|
||||
self.sftp = self.ssh.open_sftp()
|
||||
except:
|
||||
raise errors.AnsibleError("failed to open a SFTP connection")
|
||||
try:
|
||||
sftp.get(in_path, out_path)
|
||||
self.sftp.get(in_path, out_path)
|
||||
except IOError:
|
||||
raise errors.AnsibleError("failed to transfer file from %s" % in_path)
|
||||
sftp.close()
|
||||
|
||||
def close(self):
|
||||
''' terminate the connection '''
|
||||
if self.sftp is not None:
|
||||
self.sftp.close()
|
||||
self.ssh.close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user