Sending a file through winrm/powershell is limited to 3000 bytesPersist console with winrm and powershellPowershell winrm Trusted Hosts not workingwhy is monkeyrunner not working when run from a remote machine?Loop through files in a directory using PowerShellCSV File Attachment Error: 'bytes' object has no attribute 'encode'Powershell Remoting and WinRMHow to install ansible to my python at WindowsAnsible: winrm timeout issues running vsphere_guestPowerShell WinRM memory limit and Start-ProcessError “django.db.utils.IntegrityError: (1048, 'Unknown error 1048')”
Does battery condition have anything to do with macbook pro performance?
When is the earliest in Earth history when Grade 5 Titanium alloy could be made, assuming one knows the formula and has the feedstock?
Why can't we use uninitialized local variable to access static content of its type?
Why is it called a Blood Knot?
Is there an in-universe reason Harry says this or is this simply a Rowling mistake?
I feel like most of my characters are the same, what can I do?
SMTP banner mismatch with multiple MX records
What is the word for a person who destroys monuments?
Algorithm for competing cells of 0s and 1s
I reverse the source code, you negate the output!
Microservices and Stored Procedures
Applications of mathematics in clinical setting
Why are two-stroke engines nearly unheard of in aviation?
Audire, with accusative or dative?
How was ownership of property managed during the Black Death, when so many original owners had died?
Minimize taxes now that I earn more
Is the name of an interval between two notes unique and absolute?
Flying pigs arrive
Why does Canada require a minimum rate of climb for ultralights of 300 ft/min?
How should I avoid someone patenting technology in my paper/poster?
Why do things cool down?
Can one guy with a duplicator initiate a nuclear apocalypse?
Who are the people reviewing far more papers than they're submitting for review?
Which museums have artworks of all four ninja turtles' namesakes?
Sending a file through winrm/powershell is limited to 3000 bytes
Persist console with winrm and powershellPowershell winrm Trusted Hosts not workingwhy is monkeyrunner not working when run from a remote machine?Loop through files in a directory using PowerShellCSV File Attachment Error: 'bytes' object has no attribute 'encode'Powershell Remoting and WinRMHow to install ansible to my python at WindowsAnsible: winrm timeout issues running vsphere_guestPowerShell WinRM memory limit and Start-ProcessError “django.db.utils.IntegrityError: (1048, 'Unknown error 1048')”
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to send a file through WinRM/PowerShell but it seems that I'm facing a 3000 bytes limit and I don't know how to get rid of it.
From a local powershell, I can run this command and send chunks of BASE64 data successfully, I'm not limited :
while ($l=[System.Convert]::FromBase64String((Read-Host)))add-content -value ($l) -encoding byte -path 'tstfile.txt'
However, if I try to send data remotely (from a python script), the transfert starts successfully and the server stops after 3000 bytes have been written to tstfile.txt...
Here is my "simplified" code ( Python 3.5.3 + pywinrm 0.3.0 ), inspired from Ansible (https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/connection/winrm.py) :
import winrm
class TestUpload() :
def put_file(self, location, contents):
# start shell
self._shell_id = self._conn.open_shell()
ps_script='while ($l=[System.Convert]::FromBase64String((Read-Host)))add-content -value ($l) -encoding byte -path ' + location + ''
command_id = self._conn.run_command(self._shell_id, "powershell -Command %s " % (ps_script))
# send data
b64contents = base64.b64encode(contents.encode('utf-8')).decode('ascii')
for i in range(0, len(b64contents), self._step):
self._raw_send_data(self._shell_id, command_id, b64contents[i:i+self._step] )
self._raw_send_data(self._shell_id, command_id, '', eof=True)
# close shell
self._conn.cleanup_command(self._shell_id, command_id)
self._conn.close_shell(self._shell_id)
def _raw_send_data(self, shell_id, command_id,content, eof=False):
req = 'env:Envelope': self._conn._get_soap_header(
resource_uri='http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd',
action='http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Send',
shell_id=shell_id)
stream = req['env:Envelope'].setdefault('env:Body', ).setdefault(
'rsp:Send', ).setdefault('rsp:Stream', )
stream['@CommandId'] = command_id
stream['@Name'] = 'stdin'
content += 'rn'
stream['#text'] = base64.b64encode(content.encode('utf-8'))
stream['@xmlns:rsp'] = 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell'
if eof:
stream['@End'] = 'true'
res = self._conn.send_message(xmltodict.unparse(req))
This works :
t=TestUpload(step=100)
t.put_file('tstfile.txt',open('900bytesfile.txt').read())
This fails :
t=TestUpload(step=100)
t.put_file('tstfile.txt',open('9000bytesfile.txt').read())
Traceback (most recent call last):
File "/opt/environments/pypy/site-packages/winrm/transport.py", line 262, in _send_message_request
response.raise_for_status()
File "/opt/environments/pypy/site-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: for url: https://win-srv1.local.activcloud.eu:5986/wsman
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/environments/pypy/site-packages/winrm/protocol.py", line 234, in send_message
resp = self.transport.send_message(message)
File "/opt/environments/pypy/site-packages/winrm/transport.py", line 256, in send_message
response = self._send_message_request(prepared_request, message)
File "/opt/environments/pypy/site-packages/winrm/transport.py", line 273, in _send_message_request
raise WinRMTransportError('http', ex.response.status_code, response_text)
winrm.exceptions.WinRMTransportError: Bad HTTP response returned from server. Code 500
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/opt/repos/poc4/tst.py", line 158, in put_file
self._raw_send_data(self._shell_id, command_id, b64contents[i:i+self._step] )
File "/opt/repos/poc4/tst.py", line 332, in _raw_send_data
res = self._conn.send_message(xmltodict.unparse(req))
File "/opt/environments/pypy/site-packages/winrm/protocol.py", line 256, in send_message
raise WinRMOperationTimeoutError()
winrm.exceptions.WinRMOperationTimeoutError
I've got no error messages (except the timeout), I didn't find anything in the server logs, my only clue is that the file is 3000 bytes length on the server side (the data inside are correct) :
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 3/28/2019 2:52 PM 3000 tstfile.txt
Does anybody have an an idea ?
Maybe check if ansible is able to run that command with more than 3000 bytes of data ?
python powershell ansible winrm
add a comment
|
I'm trying to send a file through WinRM/PowerShell but it seems that I'm facing a 3000 bytes limit and I don't know how to get rid of it.
From a local powershell, I can run this command and send chunks of BASE64 data successfully, I'm not limited :
while ($l=[System.Convert]::FromBase64String((Read-Host)))add-content -value ($l) -encoding byte -path 'tstfile.txt'
However, if I try to send data remotely (from a python script), the transfert starts successfully and the server stops after 3000 bytes have been written to tstfile.txt...
Here is my "simplified" code ( Python 3.5.3 + pywinrm 0.3.0 ), inspired from Ansible (https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/connection/winrm.py) :
import winrm
class TestUpload() :
def put_file(self, location, contents):
# start shell
self._shell_id = self._conn.open_shell()
ps_script='while ($l=[System.Convert]::FromBase64String((Read-Host)))add-content -value ($l) -encoding byte -path ' + location + ''
command_id = self._conn.run_command(self._shell_id, "powershell -Command %s " % (ps_script))
# send data
b64contents = base64.b64encode(contents.encode('utf-8')).decode('ascii')
for i in range(0, len(b64contents), self._step):
self._raw_send_data(self._shell_id, command_id, b64contents[i:i+self._step] )
self._raw_send_data(self._shell_id, command_id, '', eof=True)
# close shell
self._conn.cleanup_command(self._shell_id, command_id)
self._conn.close_shell(self._shell_id)
def _raw_send_data(self, shell_id, command_id,content, eof=False):
req = 'env:Envelope': self._conn._get_soap_header(
resource_uri='http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd',
action='http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Send',
shell_id=shell_id)
stream = req['env:Envelope'].setdefault('env:Body', ).setdefault(
'rsp:Send', ).setdefault('rsp:Stream', )
stream['@CommandId'] = command_id
stream['@Name'] = 'stdin'
content += 'rn'
stream['#text'] = base64.b64encode(content.encode('utf-8'))
stream['@xmlns:rsp'] = 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell'
if eof:
stream['@End'] = 'true'
res = self._conn.send_message(xmltodict.unparse(req))
This works :
t=TestUpload(step=100)
t.put_file('tstfile.txt',open('900bytesfile.txt').read())
This fails :
t=TestUpload(step=100)
t.put_file('tstfile.txt',open('9000bytesfile.txt').read())
Traceback (most recent call last):
File "/opt/environments/pypy/site-packages/winrm/transport.py", line 262, in _send_message_request
response.raise_for_status()
File "/opt/environments/pypy/site-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: for url: https://win-srv1.local.activcloud.eu:5986/wsman
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/environments/pypy/site-packages/winrm/protocol.py", line 234, in send_message
resp = self.transport.send_message(message)
File "/opt/environments/pypy/site-packages/winrm/transport.py", line 256, in send_message
response = self._send_message_request(prepared_request, message)
File "/opt/environments/pypy/site-packages/winrm/transport.py", line 273, in _send_message_request
raise WinRMTransportError('http', ex.response.status_code, response_text)
winrm.exceptions.WinRMTransportError: Bad HTTP response returned from server. Code 500
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/opt/repos/poc4/tst.py", line 158, in put_file
self._raw_send_data(self._shell_id, command_id, b64contents[i:i+self._step] )
File "/opt/repos/poc4/tst.py", line 332, in _raw_send_data
res = self._conn.send_message(xmltodict.unparse(req))
File "/opt/environments/pypy/site-packages/winrm/protocol.py", line 256, in send_message
raise WinRMOperationTimeoutError()
winrm.exceptions.WinRMOperationTimeoutError
I've got no error messages (except the timeout), I didn't find anything in the server logs, my only clue is that the file is 3000 bytes length on the server side (the data inside are correct) :
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 3/28/2019 2:52 PM 3000 tstfile.txt
Does anybody have an an idea ?
Maybe check if ansible is able to run that command with more than 3000 bytes of data ?
python powershell ansible winrm
add a comment
|
I'm trying to send a file through WinRM/PowerShell but it seems that I'm facing a 3000 bytes limit and I don't know how to get rid of it.
From a local powershell, I can run this command and send chunks of BASE64 data successfully, I'm not limited :
while ($l=[System.Convert]::FromBase64String((Read-Host)))add-content -value ($l) -encoding byte -path 'tstfile.txt'
However, if I try to send data remotely (from a python script), the transfert starts successfully and the server stops after 3000 bytes have been written to tstfile.txt...
Here is my "simplified" code ( Python 3.5.3 + pywinrm 0.3.0 ), inspired from Ansible (https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/connection/winrm.py) :
import winrm
class TestUpload() :
def put_file(self, location, contents):
# start shell
self._shell_id = self._conn.open_shell()
ps_script='while ($l=[System.Convert]::FromBase64String((Read-Host)))add-content -value ($l) -encoding byte -path ' + location + ''
command_id = self._conn.run_command(self._shell_id, "powershell -Command %s " % (ps_script))
# send data
b64contents = base64.b64encode(contents.encode('utf-8')).decode('ascii')
for i in range(0, len(b64contents), self._step):
self._raw_send_data(self._shell_id, command_id, b64contents[i:i+self._step] )
self._raw_send_data(self._shell_id, command_id, '', eof=True)
# close shell
self._conn.cleanup_command(self._shell_id, command_id)
self._conn.close_shell(self._shell_id)
def _raw_send_data(self, shell_id, command_id,content, eof=False):
req = 'env:Envelope': self._conn._get_soap_header(
resource_uri='http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd',
action='http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Send',
shell_id=shell_id)
stream = req['env:Envelope'].setdefault('env:Body', ).setdefault(
'rsp:Send', ).setdefault('rsp:Stream', )
stream['@CommandId'] = command_id
stream['@Name'] = 'stdin'
content += 'rn'
stream['#text'] = base64.b64encode(content.encode('utf-8'))
stream['@xmlns:rsp'] = 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell'
if eof:
stream['@End'] = 'true'
res = self._conn.send_message(xmltodict.unparse(req))
This works :
t=TestUpload(step=100)
t.put_file('tstfile.txt',open('900bytesfile.txt').read())
This fails :
t=TestUpload(step=100)
t.put_file('tstfile.txt',open('9000bytesfile.txt').read())
Traceback (most recent call last):
File "/opt/environments/pypy/site-packages/winrm/transport.py", line 262, in _send_message_request
response.raise_for_status()
File "/opt/environments/pypy/site-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: for url: https://win-srv1.local.activcloud.eu:5986/wsman
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/environments/pypy/site-packages/winrm/protocol.py", line 234, in send_message
resp = self.transport.send_message(message)
File "/opt/environments/pypy/site-packages/winrm/transport.py", line 256, in send_message
response = self._send_message_request(prepared_request, message)
File "/opt/environments/pypy/site-packages/winrm/transport.py", line 273, in _send_message_request
raise WinRMTransportError('http', ex.response.status_code, response_text)
winrm.exceptions.WinRMTransportError: Bad HTTP response returned from server. Code 500
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/opt/repos/poc4/tst.py", line 158, in put_file
self._raw_send_data(self._shell_id, command_id, b64contents[i:i+self._step] )
File "/opt/repos/poc4/tst.py", line 332, in _raw_send_data
res = self._conn.send_message(xmltodict.unparse(req))
File "/opt/environments/pypy/site-packages/winrm/protocol.py", line 256, in send_message
raise WinRMOperationTimeoutError()
winrm.exceptions.WinRMOperationTimeoutError
I've got no error messages (except the timeout), I didn't find anything in the server logs, my only clue is that the file is 3000 bytes length on the server side (the data inside are correct) :
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 3/28/2019 2:52 PM 3000 tstfile.txt
Does anybody have an an idea ?
Maybe check if ansible is able to run that command with more than 3000 bytes of data ?
python powershell ansible winrm
I'm trying to send a file through WinRM/PowerShell but it seems that I'm facing a 3000 bytes limit and I don't know how to get rid of it.
From a local powershell, I can run this command and send chunks of BASE64 data successfully, I'm not limited :
while ($l=[System.Convert]::FromBase64String((Read-Host)))add-content -value ($l) -encoding byte -path 'tstfile.txt'
However, if I try to send data remotely (from a python script), the transfert starts successfully and the server stops after 3000 bytes have been written to tstfile.txt...
Here is my "simplified" code ( Python 3.5.3 + pywinrm 0.3.0 ), inspired from Ansible (https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/connection/winrm.py) :
import winrm
class TestUpload() :
def put_file(self, location, contents):
# start shell
self._shell_id = self._conn.open_shell()
ps_script='while ($l=[System.Convert]::FromBase64String((Read-Host)))add-content -value ($l) -encoding byte -path ' + location + ''
command_id = self._conn.run_command(self._shell_id, "powershell -Command %s " % (ps_script))
# send data
b64contents = base64.b64encode(contents.encode('utf-8')).decode('ascii')
for i in range(0, len(b64contents), self._step):
self._raw_send_data(self._shell_id, command_id, b64contents[i:i+self._step] )
self._raw_send_data(self._shell_id, command_id, '', eof=True)
# close shell
self._conn.cleanup_command(self._shell_id, command_id)
self._conn.close_shell(self._shell_id)
def _raw_send_data(self, shell_id, command_id,content, eof=False):
req = 'env:Envelope': self._conn._get_soap_header(
resource_uri='http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd',
action='http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Send',
shell_id=shell_id)
stream = req['env:Envelope'].setdefault('env:Body', ).setdefault(
'rsp:Send', ).setdefault('rsp:Stream', )
stream['@CommandId'] = command_id
stream['@Name'] = 'stdin'
content += 'rn'
stream['#text'] = base64.b64encode(content.encode('utf-8'))
stream['@xmlns:rsp'] = 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell'
if eof:
stream['@End'] = 'true'
res = self._conn.send_message(xmltodict.unparse(req))
This works :
t=TestUpload(step=100)
t.put_file('tstfile.txt',open('900bytesfile.txt').read())
This fails :
t=TestUpload(step=100)
t.put_file('tstfile.txt',open('9000bytesfile.txt').read())
Traceback (most recent call last):
File "/opt/environments/pypy/site-packages/winrm/transport.py", line 262, in _send_message_request
response.raise_for_status()
File "/opt/environments/pypy/site-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: for url: https://win-srv1.local.activcloud.eu:5986/wsman
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/environments/pypy/site-packages/winrm/protocol.py", line 234, in send_message
resp = self.transport.send_message(message)
File "/opt/environments/pypy/site-packages/winrm/transport.py", line 256, in send_message
response = self._send_message_request(prepared_request, message)
File "/opt/environments/pypy/site-packages/winrm/transport.py", line 273, in _send_message_request
raise WinRMTransportError('http', ex.response.status_code, response_text)
winrm.exceptions.WinRMTransportError: Bad HTTP response returned from server. Code 500
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/opt/repos/poc4/tst.py", line 158, in put_file
self._raw_send_data(self._shell_id, command_id, b64contents[i:i+self._step] )
File "/opt/repos/poc4/tst.py", line 332, in _raw_send_data
res = self._conn.send_message(xmltodict.unparse(req))
File "/opt/environments/pypy/site-packages/winrm/protocol.py", line 256, in send_message
raise WinRMOperationTimeoutError()
winrm.exceptions.WinRMOperationTimeoutError
I've got no error messages (except the timeout), I didn't find anything in the server logs, my only clue is that the file is 3000 bytes length on the server side (the data inside are correct) :
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 3/28/2019 2:52 PM 3000 tstfile.txt
Does anybody have an an idea ?
Maybe check if ansible is able to run that command with more than 3000 bytes of data ?
python powershell ansible winrm
python powershell ansible winrm
edited Mar 29 at 7:59
Julien
asked Mar 28 at 14:11
JulienJulien
5984 silver badges8 bronze badges
5984 silver badges8 bronze badges
add a comment
|
add a comment
|
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55399698%2fsending-a-file-through-winrm-powershell-is-limited-to-3000-bytes%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55399698%2fsending-a-file-through-winrm-powershell-is-limited-to-3000-bytes%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown