親ディレクトリを作成せずにwgetでディレクトリをミラー化する方法

StackOverflow https://stackoverflow.com/questions/5043239

  •  15-11-2019
  •  | 
  •  

質問

FTPを介してフォルダをミラーリングしたいのです。

wget --mirror --user=x --password=x ftp://ftp.site.com/folder/subfolder/evendeeper
.

しかし、このようなディレクトリ構造を作成したくない:

ftp.site.com - >フォルダ - >サブフォルダ - > evendeeper

私はただ欲しい:

evendeeper

とその下のものが結果として生じる構造である。サーバー上のevendeeperのサブディレクトリのサブディレクトリのためにサブディレクトリが作成されている限り、evendeeperの内容が現在のディレクトリに巻き上げられても許容されるでしょう。

-npオプションを認識しています。これを次のリンクから親ページへのリンク(FTPを介してミラーリングしているバイナリファイルの問題)を保持するというドキュメントに従ってください。私は-ndオプションを認識していますが、これにより、evendeeperのサブディレクトリに対しても、すべてのディレクトリ構造の作成を防ぎます。

私は彼らがコマンドラインベースで、Ubuntuパッケージとして入手可能で、ウェットのように簡単に自動化されている限り、代替案を検討します。

役に立ちましたか?

解決

For a path like: ftp.site.com/a/b/c/d

-nH would download all files to the directory a/b/c/d in the current directory, and -nH --cut-dirs=3 would download all files to the directory d in the current directory.

他のヒント

-np (no parent) option will probably do what you want, tied in with -L 1 (I think, don't have a wget install before me), which limits the recursion to one level.

EDIT. ok. gah... maybe I should wait until I've had coffee.. There is a --cut or similar option, which allows you to "cut" a specified number of directories from the output path, so for /a/b/c/d, a cut of 2 would force wget to create c/d on your local machine

Instead of using:

-nH --cut-dirs=1

use:

-nH --cut-dirs=100

This will cut more directories and no folders will be created.

Note: 100 = the number of folders to skip creating. You can change 100 to any number.

I had a similar requirement and the following combination seems to be the perfect choice:

In the below example, all the files in http://url/dir1/dir2 (alone) are downloaded to local directory /dest/dir

wget  -nd -np -P /dest/dir --recursive http://url/dir1/dir2

Thanks @ffledgling for the hint on "-nd"

For the above example:

wget -nd -np --mirror --user=x --password=x ftp://ftp.site.com/folder/subfolder/evendeeper

Snippets from manual:

   -nd
   --no-directories
       Do not create a hierarchy of directories when retrieving recursively.  With this option turned on, all files will get saved to the current directory, without clobbering (if a name shows up more than once, the
       filenames will get extensions .n).


   -np
   --no-parent
       Do not ever ascend to the parent directory when retrieving recursively.  This is a useful option, since it guarantees that only the files below a certain hierarchy will be downloaded.
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top