Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib.request
- import os
- import sys
- # Check if the file URL argument is provided
- if len(sys.argv) < 2:
- print("Usage: python script.py <FileURL>")
- sys.exit(1)
- # Get the file URL from the command-line argument
- url = sys.argv[1]
- # Determine the script's directory
- script_directory = os.path.dirname(os.path.abspath(__file__))
- # Extract the file name from the URL and set the file path in the script's directory
- file_name = os.path.basename(url)
- file_path = os.path.join(script_directory, file_name)
- # Download the file
- try:
- urllib.request.urlretrieve(url, file_path)
- print("File downloaded successfully to '" + file_path + "'")
- except Exception as e:
- print("An error occurred: " + str(e))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement