Browse Source

Added implementations for all functions

master
Raphael Roberts 7 years ago
parent
commit
b37799c882
  1. 31
      copy_cert.py

31
copy_cert.py

@ -1,20 +1,37 @@
#!/usr/bin/python
import paramiko
import argparse
import os
from subprocess import list2cmdline
def connection_from_config(name):
"""Create a connection from a Host entry in the .ssh/config file"""
pass
def scp(connection, src, dst):
config = paramiko.config.SSHConfig()
cp = os.path.expanduser('~/.ssh/config')
with open(cp) as file:
config.parse(file)
info = config.lookup(name)
info['username'] = info.pop('user')
info['key_filename'] = info.pop('identityfile')
info['port'] = int(info['port'])
client = paramiko.client.SSHClient()
client.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))
client.connect(**info)
return client
def scp(connection: paramiko.sftp_client.SFTPClient, src, dst):
"""Function to copy files from src to dst using connection"""
pass
connection.put(src, dst)
def exec_remote(connection, command):
def exec_remote(connection: paramiko.SSHClient, command):
"""Function to execute specified command on conection"""
pass
if not isinstance(command, str):
command = list2cmdline(command)
stdin, stdout, stderr = connection.exec_command(command)
return stdout, stderr
if __name__ == "__main__":

Loading…
Cancel
Save