Commit 317ebab0 authored by Vitaly Lipatov's avatar Vitaly Lipatov

eget: add --list support for FTP protocol

parent a03b3ad0
...@@ -265,6 +265,11 @@ is_httpurl() ...@@ -265,6 +265,11 @@ is_httpurl()
echo "$1" | grep -q "^http://" && return echo "$1" | grep -q "^http://" && return
} }
is_ftpurl()
{
echo "$1" | grep -q "^ftp://"
}
cid_from_url() cid_from_url()
{ {
echo "$1" | sed -e 's|^ipfs://*||' -e 's|\?.*||' echo "$1" | sed -e 's|^ipfs://*||' -e 's|\?.*||'
...@@ -1994,16 +1999,18 @@ get_urls() ...@@ -1994,16 +1999,18 @@ get_urls()
return return
fi fi
# Hack: Converted markdown support local content
# https://github.com/dotnet/core/blob/main/release-notes/9.0/preview/rc1/9.0.0-rc.1.md content="$(scat "$URL")"
if false && echo "$URL" | grep -q "\.md$" ; then
scat "$URL" | sed -e 's|<|<\n|g' | grep "https*" | sed -e 's|.*\(https*://\)|\1|' -e 's|".*||g'
return
fi
# cat html, divide to lines by tags and cut off hrefs only # Detect format: HTML (contains <) or ls -l (FTP directory listing from curl)
scat "$URL" | sed -e 's|<|<\n|g' -e 's|data-file=|href=|g' -e "s|href=http|href=\"http|g" -e "s|>|\">|g" -e "s|'|\"|g" | \ if echo "$content" | grep -q '<' ; then
grep -i -o -E 'href="(.+)"' | sed -e 's|&amp;|\&|' | cut -d'"' -f2 | sed -e 's|^ *||g' -e 's| *$||g' # HTML format (wget FTP, HTTP): parse href attributes
echo "$content" | sed -e 's|<|<\n|g' -e 's|data-file=|href=|g' -e "s|href=http|href=\"http|g" -e "s|>|\">|g" -e "s|'|\"|g" | \
grep -i -o -E 'href="(.+)"' | sed -e 's|&amp;|\&|' | cut -d'"' -f2 | sed -e 's|^ *||g' -e 's| *$||g'
else
# ls -l format (curl FTP): extract last field (filename)
echo "$content" | awk '{print $NF}'
fi
} }
# Check that URL is provided (unless using -i|--input-file) # Check that URL is provided (unless using -i|--input-file)
...@@ -2120,15 +2127,6 @@ else ...@@ -2120,15 +2127,6 @@ else
[ -n "$3" ] && fatal "too many args: extra '$3'. May be you need use quotes for arg with wildcards." [ -n "$3" ] && fatal "too many args: extra '$3'. May be you need use quotes for arg with wildcards."
fi fi
# TODO: curl?
# If ftp protocol, just download
if echo "$URL" | grep -q "^ftp://" ; then
[ -n "$LISTONLY" ] && fatal "TODO: list files for ftp:// is not supported yet"
sget "$1" "$TARGETFILE"
exit
fi
if [ -n "$LISTONLY" ] ; then if [ -n "$LISTONLY" ] ; then
for fn in $(get_urls | filter_glob "$MASK" | filter_order) ; do for fn in $(get_urls | filter_glob "$MASK" | filter_order) ; do
is_url "$fn" && echo "$fn" && continue is_url "$fn" && echo "$fn" && continue
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment