(self, local_items, remote_path=None, randomize_fname=False, url_to_bytes_fn=None)
| 3640 | return downloaded |
| 3641 | |
| 3642 | def upload(self, local_items, remote_path=None, randomize_fname=False, url_to_bytes_fn=None): |
| 3643 | |
| 3644 | url_to_bytes_fn = url_to_bytes_fn or url_to_bytes |
| 3645 | destination = remote_path or self.cwd |
| 3646 | |
| 3647 | if not self.write_access(destination): |
| 3648 | return [] |
| 3649 | |
| 3650 | # Initialization |
| 3651 | try: |
| 3652 | local_items = [item if re.match(r'(http|ftp)s?://', item, re.IGNORECASE)\ |
| 3653 | else normalize_path(item) for item in shlex.split(local_items)] |
| 3654 | |
| 3655 | except ValueError as e: |
| 3656 | logger.error(e) |
| 3657 | return [] |
| 3658 | |
| 3659 | # Check for necessary binaries |
| 3660 | if self.OS == 'Unix' and not self.agent: |
| 3661 | dependencies = ['echo', 'base64', 'tar', 'rm'] |
| 3662 | for binary in dependencies: |
| 3663 | if not self.bin[binary]: |
| 3664 | logger.error(f"'{binary}' binary is not available at the target. Cannot upload...") |
| 3665 | return [] |
| 3666 | |
| 3667 | # Resolve items |
| 3668 | resolved_items = [] |
| 3669 | for item in local_items: |
| 3670 | # Download URL |
| 3671 | if re.match(r'(http|ftp)s?://', item, re.IGNORECASE): |
| 3672 | try: |
| 3673 | filename, item = url_to_bytes_fn(item) |
| 3674 | if not item: |
| 3675 | continue |
| 3676 | resolved_items.append((filename, item)) |
| 3677 | except Exception as e: |
| 3678 | logger.error(e) |
| 3679 | else: |
| 3680 | if os.path.isabs(item): |
| 3681 | items = list(Path('/').glob(item.lstrip('/'))) |
| 3682 | else: |
| 3683 | items = list(Path().glob(item)) |
| 3684 | if items: |
| 3685 | resolved_items.extend(items) |
| 3686 | else: |
| 3687 | logger.error(f"No such file or directory: {item}") |
| 3688 | |
| 3689 | if not resolved_items: |
| 3690 | return [] |
| 3691 | |
| 3692 | if self.OS == 'Unix': |
| 3693 | # Get remote available space |
| 3694 | remote_space = remote_block_size = None |
| 3695 | if self.agent: |
| 3696 | response = self.exec(f""" |
| 3697 | stats = os.statvfs(normalize_path('{destination}')) |
| 3698 | stdout_stream << (str(stats.f_bavail) + ';' + str(stats.f_frsize)).encode() |
| 3699 | """, python=True, value=True) |
no test coverage detected