2009-07-31 34 views
5

我只想從我的服務器下載.htm或.html文件。我試圖使用ncftpget,甚至wget,但只有有限的成功。如何使用命令行從Linux服務器中僅遞歸地ftp特定文件類型?

與ncftpget我可以下載整個樹結構沒有問題,但似乎無法指定我想要的文件,它可能是全部或沒有。

如果我指定的文件類型是這樣,它只是看起來的頂層文件夾:

ncftpget -R -u myuser -p mypass ftp://ftp.myserver.com/public_html/*.htm ./local_folder 

如果我這樣做,它下載整個網站,而不僅僅是.htm文件:

ncftpget -R -u myuser -p mypass ftp://ftp.myserver.com/public_html/ ./local_folder *.htm 

我可以使用ncftp來做到這一點,或者我應該使用另一種工具嗎?

回答

4

你可以用wget的

wget -r -np -A "*.htm*" ftp://site/dir 

或做它:

wget -m -np -A "*.htm*" ftp://user:[email protected]/dir 

然而,按照Types of Files

注意,這兩個選項不影響HTML的下載文件(由.htm.html文件名前綴確定)。對於所有用戶來說,這種行爲可能並不理想,並且可能會針對未來版本的Wget進行更改。

+0

例如,您應該使用`* .htm *'`將* * .htm *``傳遞給wget。 – Jazz 2009-07-31 22:51:53

0

ncftpget是否理解dir globs?

嘗試

ncftpget -R -u myuser -p mypass ftp://ftp.myserver.com/public_html/**/*.htm ./local_folder 

**表示任意數量的目錄。

+0

不起作用 – 2009-07-31 22:52:40

0

wget命令瞭解常用的unix文件通配語法。

wget -r -np --ftp-user=username --ftp-password=password "ftp://example.com/path/to/dir/*.htm" 

相反,您可以使用-A選項,它接受一個逗號分隔的文件名後綴或模式接受的列表。

wget -A '*.htm' 

-R選項的-A對面,所以你可以用它來指定模式不去取。

警告:確保引用模式!否則,你的外殼可能會擴大glob本身,導致意想不到的結果。

另外!請參閱服務器故障上的"Using wget to recursively download whole FTP directories"問題。

相關問題