Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copy() timeout #182

Open
shreyamalviya opened this issue Dec 13, 2023 · 3 comments
Open

copy() timeout #182

shreyamalviya opened this issue Dec 13, 2023 · 3 comments

Comments

@shreyamalviya
Copy link

Hi,

In our code, we're copying a file to a remote machine using pypsrp.Client.copy:

def copy(
self,
src: str,
dest: str,
configuration_name: str = DEFAULT_CONFIGURATION_NAME,
expand_variables: bool = False,
) -> str:
"""
Copies a single file from the current host to the remote Windows host.
This can be quite slow when it comes to large files due to the
limitations of WinRM but it is designed to be as fast as it can be.
During the copy process, the bytes will be stored in a temporary file
before being copied.
When copying it will replace the file at dest if one already exists. It
also will verify the checksum of the copied file is the same as the
actual file locally before copying the file to the path at dest.
:param src: The path to the local file
:param dest: The path to the destination file on the Windows host
:param configuration_name: The PowerShell configuration endpoint to
use when copying the file.
:param expand_variables: Expand variables in path. Disabled by default
Enable for cmd like expansion (for example %TMP% in path)
:return: The absolute path of the file on the Windows host
"""

There seems to be no way to set a timeout for the operation. Is there some way to do this that I'm missing or is this not a feature that's implemented yet?

@jborean93
Copy link
Owner

There is no way to currently do so, you can configure the socket timeouts like a connection and read timeout but it will continue to write to the file during that time.

@shreyamalviya
Copy link
Author

you can configure the socket timeouts like a connection and read timeout

I don't think I understand. How?

@jborean93
Copy link
Owner

When you create the client you specify it through the kwargs

from pypsrp.client import Client

with Client("server", connection_timeout=30, read_timeout=30) as client:
    client.copy(...)

The kwargs here are passed through to the WSMan object

pypsrp/src/pypsrp/wsman.py

Lines 109 to 132 in d2a3eca

class WSMan(object):
def __init__(
self,
server: str,
max_envelope_size: int = 153600,
operation_timeout: int = 20,
port: typing.Optional[int] = None,
username: typing.Optional[str] = None,
password: typing.Optional[str] = None,
ssl: bool = True,
path: str = "wsman",
auth: str = "negotiate",
cert_validation: bool = True,
connection_timeout: int = 30,
encryption: str = "auto",
proxy: typing.Optional[str] = None,
no_proxy: bool = False,
locale: str = "en-US",
data_locale: typing.Optional[str] = None,
read_timeout: int = 30,
reconnection_retries: int = 0,
reconnection_backoff: float = 2.0,
**kwargs: typing.Any,
) -> None:
. Please take not that if you set read_timeout, then operation_timeout should also be set to something that is lower than it.

Remember that this won't set the global timeout for the operation, there is no way to do so right now. This only configures the timeout it takes to connect to the host and the time in which it will wait for a response on any WSMan request sent during this process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants