Python scp.SCPException() Examples
The following are 8
code examples of scp.SCPException().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
scp
, or try the search function
.
Example #1
Source File: RemoteCrashFetcher.py From LuckyCAT with GNU General Public License v3.0 | 6 votes |
def copy_crashes_dir_with_scp(self, ssh): parent_dir_of_crashes_dir = os.path.dirname(config.crashes_dir) try: scp = SCPClient(ssh.get_transport()) scp.get(remote_path=config.remote_crashes_dir, local_path=parent_dir_of_crashes_dir, recursive=True, preserve_times=True) print("successfully fetched!!") except SCPException as e: print("Operation error: %s" % e) except SocketTimeout: """ the fetcher will need multiple attempts if the ssh connection is bad and/or the copy dir is big """ print('SocketTimeout') except PipeTimeout as pipetimeout: print("timeout was reached on a read from a buffered Pipe: %s" % pipetimeout) finally: scp.close()
Example #2
Source File: paramiko_helper.py From galaxia with Apache License 2.0 | 6 votes |
def loginandcopydir(hostname,uname,pwd,sfile,tfile,recursive,preserve_times): try: log.info("Establishing ssh connection") client = getsshClient() client.load_system_host_keys() client.connect(hostname) #,username=uname)#,password=pwd) except paramiko.AuthenticationException: print("Authentication failed, please verify your credentials: %s") except paramiko.SSHException as sshException: print("Unable to establish SSH connection: %s" % sshException) except paramiko.BadHostKeyException as badHostKeyException: print("Unable to verify server's host key: %s" % badHostKeyException) except Exception as e: print(e.args) try: scpclient = scp.SCPClient(client.get_transport()) scpclient.put(sfile,tfile,recursive,preserve_times) except scp.SCPException as e: print("Operation error: %s", e) # Deprecated
Example #3
Source File: paramiko_helper.py From galaxia with Apache License 2.0 | 6 votes |
def loginandcopy(hostname,uname,pwd,sfile,tfile): try: log.info("Establishing ssh connection") client = getsshClient() client.load_system_host_keys() client.connect(hostname)#,username=uname)#,password=pwd) except paramiko.AuthenticationException: print("Authentication failed, please verify your credentials: %s") except paramiko.SSHException as sshException: print("Unable to establish SSH connection: %s" % sshException) except paramiko.BadHostKeyException as badHostKeyException: print("Unable to verify server's host key: %s" % badHostKeyException) except Exception as e: print(e.args) try: log.info("Getting SCP Client") scpclient = scp.SCPClient(client.get_transport()) log.info(scpclient) log.info("Hostname: %s", hostname) log.info("source file: %s", sfile) log.info("target file: %s", tfile) scpclient.put(sfile,tfile) except scp.SCPException as e: print("Operation error: %s", e)
Example #4
Source File: redpitaya.py From pyrpl with GNU General Public License v3.0 | 5 votes |
def installserver(self): self.endserver() sleep(self.parameters['delay']) self.ssh.ask('rw') sleep(self.parameters['delay']) self.ssh.ask('mkdir ' + self.parameters['serverdirname']) sleep(self.parameters['delay']) self.ssh.ask("cd " + self.parameters['serverdirname']) #try both versions for serverfile in ['monitor_server','monitor_server_0.95']: sleep(self.parameters['delay']) try: self.ssh.scp.put( os.path.join(os.path.abspath(os.path.dirname(__file__)), 'monitor_server', serverfile), self.parameters['serverdirname'] + self.parameters['monitor_server_name']) except (SCPException, SSHException): self.logger.exception("Upload error. Try again after rebooting your RedPitaya..") sleep(self.parameters['delay']) self.ssh.ask('chmod 755 ./'+self.parameters['monitor_server_name']) sleep(self.parameters['delay']) self.ssh.ask('ro') result = self.ssh.ask("./"+self.parameters['monitor_server_name']+" "+ str(self.parameters['port'])) sleep(self.parameters['delay']) result += self.ssh.ask() if not "sh" in result: self.logger.debug("Server application started on port %d", self.parameters['port']) return self.parameters['port'] else: # means we tried the wrong binary version. make sure server is not running and try again with next file self.endserver() #try once more on a different port if self.parameters['port'] == self.parameters['defaultport']: self.parameters['port'] = random.randint(self.parameters['defaultport'],50000) self.logger.warning("Problems to start the server application. Trying again with a different port number %d",self.parameters['port']) return self.installserver() self.logger.error("Server application could not be started. Try to recompile monitor_server on your RedPitaya (see manual). ") return None
Example #5
Source File: CI.py From bubble-toolkit with Apache License 2.0 | 4 votes |
def cleanup(self, jsonpath=None, vm=None, name_path=None, result_filter=None, collect_logs=True): """Collect all data and cleanup VM's and images Example: ci = CI('/data/shared/marvin/marvin.json') ci.cleanup(config=config, jsonpath='zones[*].pods[*].clusters[*].hosts[*]', namepath='url', filter=lambda x: x.split('/')[::-1][0]) :param jsonpath: JSONPath to filter out JSON :param vm: Name of the instance to remove :param name_path: Optional parameter to filter out json :param result_filter: Optional lambda to use on filtered result :param collect_logs: Collect logs and coverage files """ for i in parse(jsonpath).find(self.config): properties = i.value username = properties.get('username', properties.get('user', 'root')) password = properties.get('password', properties.get('passwd', 'password')) if name_path: vm = parse(name_path).find(properties)[0].value if result_filter: vm = result_filter(vm) if collect_logs: print("==> Collecting Logs and Code Coverage Report from %s" % vm) # TODO: Copy logs and coverage reports from HV and SCP them # collect_files_from_vm ${csip} ${csuser} ${cspass} "/var/log/cosmic/management/*.log*" "cs${i}-management-logs/" if vm.startswith('cs'): src = "/var/log/cosmic/management/*.log*" dstdir = "%s-management-logs" % vm hostname = properties['mgtSvrIp'] else: src = "/var/log/cosmic/agent/*.log*" dstdir = "%s-agent-logs" % vm hostname = vm if not os.path.exists(dstdir): os.makedirs(dstdir) try: self.collect_files_from_vm(hostname=hostname, username=username, password=password, src=src, dst="%s" % dstdir) except (scp.SCPException, paramiko.ssh_exception) as e: print("ERROR: %s" % e.message) print("==> Destroying VM %s" % vm) # FIXME: Create library for this instead of a subprocess subprocess.call(['/data/shared/deploy/kvm_local_deploy.py', '-x', vm])
Example #6
Source File: wrap.py From jaide with GNU General Public License v2.0 | 4 votes |
def pull(jaide, source, destination, progress, multi): """ Copy file(s) from a device to the local machine. @param jaide: The jaide connection to the device. @type jaide: jaide.Jaide object @param source: The source filepath on the junos device to pull. @type source: str @param destination: the destination filepath on the local device for | the files. @type destination: str @param progress: Flagged to True if the user desires to see the status | as the copy happens. @type progress: bool @param multi: Flagged to true if we're copying from multiple devices. | Used to name the destination files. @type multi: bool @returns: The output of the copy. @rtype str """ output = color('Retrieving %s:%s, and putting it in %s\n' % (jaide.host, source, path.normpath(destination)), 'yel') # Check if the destination ends in a '/', if not, we need to add it. destination = destination + '/' if destination[-1] != '/' else destination # If the source ends in a slash, we need to remove it. For copying # directories, this will ensure that the local directory gets created # remotely, and not just the contents. Basically, this forces the behavior # 'scp -r /var/log /dest/loc' instead of 'scp -r /var/log/* /dest/loc' source = source[:-1] if source[-1] == '/' else source source_file = path.basename(source) if not '' else path.basename(path.join(source, '..')) dest_file = destination + jaide.host + '_' + source_file if multi else destination + source_file try: jaide.scp_pull(source, dest_file, progress) if progress: # move to the next line if we were printing the progress click.echo('') except SCPException as e: output += color('!!! Error during copy from ' + jaide.host + '. Some files may have failed to transfer. SCP Module' ' error:\n' + str(e) + ' !!!\n', 'red') except (IOError, OSError) as e: output += color('!!! The local filepath was not found! Note that \'~\'' ' cannot be used. Error:\n' + str(e) + ' !!!\n', 'red') else: output += color('Received %s:%s and stored it in %s.\n' % (jaide.host, source, path.normpath(dest_file))) return output
Example #7
Source File: wrap.py From jaide with GNU General Public License v2.0 | 4 votes |
def push(jaide, source, destination, progress, multi=False): """ Copy file(s) from the local machine to a junos device. @param jaide: The jaide connection to the device. @type jaide: jaide.Jaide object @param source: The source filepath on the junos device to pull. @type source: str @param destination: the destination filepath on the local device for | the files. @type destination: str @param progress: Flagged to True if the user desires to see the status | as the copy happens. @type progress: bool @param multi: Flagged to true if we're copying from multiple devices. | Not needed in this function @type multi: bool @returns: The output of the copy. @rtype str """ output = color('Pushing %s to %s:%s\n' % (source, jaide.host, destination), 'yel') # Check if the destination ends in a '/', if not, we need to add it. destination = destination + '/' if destination[-1] != '/' else destination # If the source ends in a slash, we need to remove it. For copying # directories, this will ensure that the local directory gets created # remotely, and not just the contents. Basically, this forces the behavior # 'scp -r /var/log /dest/loc' instead of 'scp -r /var/log/* /dest/loc' source = source[:-1] if source[-1] == '/' else source try: jaide.scp_push(source, destination, progress) if progress: click.echo('') except SCPException as e: output += color('!!! Error during copy from ' + jaide.host + '. Some files may have failed to transfer. SCP Module' ' error:\n' + str(e) + ' !!!\n', 'red') except (IOError, OSError) as e: output += color('!!! The local filepath was not found! Note that \'~\'' ' cannot be used. Error:\n' + str(e) + ' !!!\n', 'red') else: output += color('Pushed %s to %s:%s\n' % (source, jaide.host, destination)) return output
Example #8
Source File: redpitaya.py From pyrpl with GNU General Public License v3.0 | 4 votes |
def update_fpga(self, filename=None): if filename is None: try: source = self.parameters['filename'] except KeyError: source = None self.end() sleep(self.parameters['delay']) self.ssh.ask('rw') sleep(self.parameters['delay']) self.ssh.ask('mkdir ' + self.parameters['serverdirname']) sleep(self.parameters['delay']) if source is None or not os.path.isfile(source): if source is not None: self.logger.warning('Desired bitfile "%s" does not exist. Using default file.', source) source = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'fpga', 'red_pitaya.bin') if not os.path.isfile(source): raise IOError("Wrong filename", "The fpga bitfile was not found at the expected location. Try passing the arguments " "dirname=\"c://github//pyrpl//pyrpl//\" adapted to your installation directory of pyrpl " "and filename=\"red_pitaya.bin\"! Current dirname: " + self.parameters['dirname'] + " current filename: "+self.parameters['filename']) for i in range(3): try: self.ssh.scp.put(source, os.path.join(self.parameters['serverdirname'], self.parameters['serverbinfilename'])) except (SCPException, SSHException): # try again before failing self.start_ssh() sleep(self.parameters['delay']) else: break # kill all other servers to prevent reading while fpga is flashed self.end() self.ssh.ask('killall nginx') self.ssh.ask('systemctl stop redpitaya_nginx') # for 0.94 and higher self.ssh.ask('cat ' + os.path.join(self.parameters['serverdirname'], self.parameters['serverbinfilename']) + ' > //dev//xdevcfg') sleep(self.parameters['delay']) self.ssh.ask('rm -f '+ os.path.join(self.parameters['serverdirname'], self.parameters['serverbinfilename'])) self.ssh.ask("nginx -p //opt//www//") self.ssh.ask('systemctl start redpitaya_nginx') # for 0.94 and higher #needs test sleep(self.parameters['delay']) self.ssh.ask('ro')