Search code examples
python-3.xhttpsdownloadwgetfile-transfer

How do I pass username and password with a wget.download() request in Python3


To download a file from a web server, I do below -

import wget

url = "https:xxxxx/file"

iso_filename = wget.download(url, '/Users/xxxxx/Downloads/')

Now, I am trying to download a file from a website which requires authentication.

User credentials involve special characters - @, # etc

I would like to know a way of how to supply username and password in python3 while using wget ?

I would prefer to use wget unless there isn't any other option to overcome this issue.

Any advise would be highly appreciated.


Solution

  • I finally gave up on using wget.download(), what worked for me is scp, explained as below -

    sshpass -f 'path to psw file' scp -r user@10.X.X.X:/file_path /path_to dowload_file
    

    ex:

    sshpass -f 'usr/bin/psw.txt' scp -r user@10.X.X.X:/usr/bin/ubuntu.iso /remote/user/iso
    

    psw.txt to pass password in a file to avoid been listed in bash history etc...