0

I want down load "*_ice.nc" files in ftp. so..

library

import wget
import math
import re 
from urllib import request

adress and file list

url = "ftp://ftp.hycom.org/datasets/GLBy0.08/expt_93.0/data/hindcasts/2021/" #url
html = request.urlopen(url) #open url
html_contents = str(html.read().decode("cp949"))
url_list = re.findall(r"(ftp)(.+)(_ice.nc)", html_contents)

loop for download

for url in url_list: #loop 
    url_full="".join(url) #tuple to string
    file_name=url_full.split("/")[-1]
    print('\nDownloading ' + file_name) 
    wget.download(url_full) #down with wget

but error messege occured like this (ValueError: unknown url type: 'ftp%20%20%20%20%20%20ftp%20%20%20%20%20%20382663848%20Jan%2002%20%202021%20hycom_GLBy0.08_930_2021010112_t000_ice.nc')

could i get some help?

1 Answer 1

1

After decoding

ftp%20%20%20%20%20%20ftp%20%20%20%20%20%20382663848%20Jan%2002%20%202021%20hycom_GLBy0.08_930_2021010112_t000_ice.nc

is

ftp      ftp      382663848 Jan 02  2021 hycom_GLBy0.08_930_2021010112_t000_ice.nc

which clearly is not legal ftp address. You need alter your code so it will be

ftp://ftp.hycom.org/datasets/GLBy0.08/expt_93.0/data/hindcasts/2021/hycom_GLBy0.08_930_2021010112_t000_ice.nc

I suggest temporarily replacing wget.download(url_full) using print(url_full), then apply changes to get desired output and then reverting to wget.download(url_full).

Not the answer you're looking for? Browse other questions tagged or ask your own question.