wget
保存するパスがまだない間はできません。つまり、wget
存在しない保存パスでは機能しません。例:
wget -O /path/to/image/new_image.jpg http://www.example.com/old_image.jpg
以前に存在していなかった場合/path/to/image/
は、常に次を返します。
No such file or directory
パスを自動的に作成して保存するようにするにはどうすればよいですか?
試すcurl
curl http://www.site.org/image.jpg --create-dirs -o /path/to/save/images.jpg
mkdir -p /path/i/want && wget -O /path/i/want/image.jpg http://www.com/image.jpg
wgetを使用してファイルを新しいディレクトリにダウンロードするには、 :--directory-prefix
なし で使用します。-O
wget --directory-prefix=/new/directory/ http://www.example.com/old_image.jpg
-O new_file
と組み合わせて使用すると--directory-prefix
、新しいディレクトリ構造は作成されず、新しいファイルが現在のディレクトリに保存されます。指定すると、「そのようなファイルまたはディレクトリはありません」というエラーで失敗することもあります。-O /new/directory/new_file
このコマンドでフォルダが存在しない場合は、フォルダを作成できました。
wget -N http://www.example.com/old_image.jpg -P /path/to/image
wgetは、ディレクトリ構造を作成せずにファイルを取得するだけです(mkdir -p / path / to / image /)。これは自分で行う必要があります。
mkdir -p /path/to/image/ && wget -O /path/to/image/new_image.jpg http://www.example.com/old_image.jpg
パラメータを使用して、ディレクトリを作成するようにwgetに指示できます(したがって、mkdirを使用する必要はありません)。--force-directories
一緒にこれは
wget --force-directories -O /path/to/image/new_image.jpg http://www.example.com/old_image.jpg
たくさん検索した後、私はついに存在しないパスをダウンロードするために使用する方法をwget
見つけました。
wget -q --show-progress -c -nc -r -nH -i "$1"
=====
Clarification
-q
--quiet --show-progress
Kill annoying output but keep the progress-bar
-c
--continue
Resume download if the connection lost
-nc
--no-clobber
Overwriting file if exists
-r
--recursive
Download in recursive mode (What topic creator asked for!)
-nH
--no-host-directories
Tell wget do not use the domain as a directory (for e.g: https://example.com/what/you/need
- without this option, it will download to "example.com/what/you/need")
-i
--input-file
File with URLs need to be download (in case you want to download a lot of URLs,
otherwise just remove this option)
Happy wget-ing!