Dump NAS Directory Tree To File

There are a few different Ubuntu — FileZilla (recommended & included), command line ftp (ok), and ncftp/lftp.  It’s worth having both ncftp and lftp around…but in general, I have found lftp more handy when it comes to NAS interactions.

Install

$ apt-get install lftp

Usage

$ lftp -u <my id>,<my password> <my nas ip address> -e "set ssl:verify-certificate no; find -l /<my path>; quit" > my_nas_output.txt

Make sure to use a id/password combo that is read only and restricted to just the areas of the NAS you don’t care about.

The output is in an extended file listing not to dissimiliar from ye olde ls -laR and will contain every file and directory (that your id can access). Once you’ve dumped it to a file, you can use whatever tool you want to examine your /NAS contents.

Common tasks

What do you do once you have a local my_nas_output.txt?

#Figure out if a file is in your nas or not
$ grep "my_file.txt" my_nas_output.txt

#List all directories
$ awk '/^d/' my_nas_output.txt

#No, list ONLY directories
$ awk '/^d/' my_nas_output.txt | sed 's/^.* \///g'

#Remember abcde? Say we put all our ripped files in:
#  /Music/Artist/Artist - Album.  
# Let's list only the last two subdirectories and exlcuding the
# common "Music" directory.
#
$ awk '/^d/' my_nas_output.txt | sed 's/^.* \///g' | awk -F / '{print $(NF-2),"-",$(NF-1)}' | grep -v Music | sort > my_music.txt
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s