Iam trying to open ftp url in file explorer.
url = QUrl("ftp://192.168.1.127:15010/intrusionfiles/detectionfiles/",QUrl.TolerantMode)
url.setScheme("ftp")
QDesktopServices.openUrl(url)
When I try it this way it asks how I want it to open. How do I get it to open directly in file explorer?
Solved my problem by starting explorer.exe using qprocess.
p = QProcess()
p.startDetached("C:\\Windows\\explorer.exe", ["ftp://admin:admin#192.168.1.127:15010/intrusionfiles/detectionfiles/21-09-21/"])
Related
How can I send a file to the browser in a headless selenium session (as opposed to clicking on an "upload" button)?
For example, how do I add a file to a form like this without using the gui:
In most cases there is an input element with type file there, so you can directly send your file path to it.
For example if your file path on the disk is C:\\Users\\Desktop\\test.png your code will be:
file_path = "C:\\Users\\Desktop\\test.png"
upload_element = driver.find_element_by_xpath("//input[#type='file']")
upload_element.send_keys(file_path)
I tried using wget:
url = https://yts.lt/torrent/download/A4A68F25347C709B55ED2DF946507C413D636DCA
wget.download(url, 'c:/path/')
The result was that I got a file with the name A4A68F25347C709B55ED2DF946507C413D636DCA and without any extension.
Whereas when I put the link in the navigator bar and click enter, a torrent file gets downloaded.
EDIT:
Answer must be generic not case dependent.
It must be a way to download .torrent files with their original name.
You can get the filename inside the content-disposition header, i.e.:
import re, requests, traceback
try:
url = "https://yts.lt/torrent/download/A4A68F25347C709B55ED2DF946507C413D636DCA"
r = requests.get(url)
d = r.headers['content-disposition']
fname = re.findall('filename="(.+)"', d)
if fname:
with open(fname[0], 'wb') as f:
f.write(r.content)
except:
print(traceback.format_exc())
Py3 Demo
The code above is for python3. I don't have python2 installed and I normally don't post code without testing it.
Have a look at https://stackoverflow.com/a/11783325/797495, the method is the same.
I found an a way that gets the torrent files downloaded with their original name like as they were actually downloaded by putting the link in the browser's nav bar.
The solution consists of opening the user's browser from Python :
import webbrowser
url = "https://yts.lt/torrent/download/A4A68F25347C709B55ED2DF946507C413D636DCA"
webbrowser.open(url, new=0, autoraise=True)
Read more:
Call to operating system to open url?
However the downside is :
I don't get the option to choose the folder where I want to save the
file (unless I changed it in the browser but still, in case I want to save
torrents that matches some criteria in an other
path, it won't be possible).
And of course, your browser goes insane opening all those links XD
I need to open the page automatically and download the file returned by the server
I have a simple code to open the page and download the content. I am also pulling the headers so I know the name of the returned file. below is the code
downloadPageRequest = self.reqSession.get( self.url_file ,stream=True)
headers = downloadPageRequest.headers
if 'content-disposition' in headers:
file_name = re.findall("filename=(.+)", headers['content-disposition'])
that's what I got, it returns an array with the filename, but now I am stuck and have no idea how to open and go through returned excel file
this has to be done using requests, that's why i cannot use any other method (e.g selenium)
will be thankful for your support
I'm trying to upload a file to my VPS (hosted by GoDaddy) via Python's ftplib library:
from ftplib import FTP
session = FTP('ftp.wangsibo.xyz','wsb','Wsb.139764')
file = open('source10.png','rb')
session.storbinary('store_source10.png', file)
file.close()
session.quit()
However it gets stuck at line 4 (the file is only a few k's and it's taking minutes). The same thing happens when I'm trying to read using retrbinary.
I've tried using FileZilla and it worked fine. Any suggestions?
FTP.storbinary(command, fp[, blocksize, callback, rest])
Store a file in binary transfer mode. command should be an appropriate
STOR command: "STOR filename". fp is an open file object which is read
until EOF using its read() method in blocks of size blocksize to
provide the data to be stored.
store_source10.png is not a command, you can try to use STOR source10.png.
e.g.
from ftplib import FTP
session = FTP('ftp.wangsibo.xyz','wsb','Wsb.139764')
file=open('source10.png','rb')
session.storbinary('STOR source10.png',file)
file.close()
session.quit()
I want to make a python script that opens a text file that the user can update before continuing (for configurations) and then continue the script once the text editor closes. Is there something in python that will allow me to do this?
on windows using notepad:
import os
cf = "config.txt" # or full path if you like
if not os.path.exists(cf):
f = open(cf,"w"); f.close() # create to avoid notepad message
os.system("notepad "+cf) # call waits until user closes the file
# now the file has been edited by the user