mirror of
https://github.com/simon987/od-database.git
synced 2025-04-19 18:36:44 +00:00
FTP url validation
This commit is contained in:
parent
0304c98a31
commit
d8c16d53e6
10
od_util.py
10
od_util.py
@ -5,6 +5,7 @@ import os
|
|||||||
import validators
|
import validators
|
||||||
import re
|
import re
|
||||||
import mimetypes
|
import mimetypes
|
||||||
|
from ftplib import FTP
|
||||||
|
|
||||||
|
|
||||||
def truncate_path(path, max_len):
|
def truncate_path(path, max_len):
|
||||||
@ -42,7 +43,7 @@ def is_valid_url(url):
|
|||||||
if not url.endswith("/"):
|
if not url.endswith("/"):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not url.startswith(("http://", "https://")):
|
if not url.startswith(("http://", "https://", "ftp://")):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return validators.url(url)
|
return validators.url(url)
|
||||||
@ -67,6 +68,13 @@ def is_od(url):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if url.startswith("ftp://"):
|
||||||
|
url = url[6:-1] # Remove schema and trailing slash
|
||||||
|
ftp = FTP(url)
|
||||||
|
ftp.login()
|
||||||
|
ftp.close()
|
||||||
|
return True
|
||||||
|
else:
|
||||||
r = requests.get(url, timeout=15, allow_redirects=False)
|
r = requests.get(url, timeout=15, allow_redirects=False)
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
print("No redirects allowed!")
|
print("No redirects allowed!")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user