mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Don't close paramiko SFTP multiple times in the same runner pass. Noticeable performance increase.
This commit is contained in:
parent
8b50ad7e85
commit
4c83c274e0
1 changed files with 6 additions and 6 deletions
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in a new issue