This sed script takes a ftp file list generated by 'mdir -R' and outputs a ftp script to recursively get contents of ftp.
I use this in a hosting provider that does not provide means of making backups or zipping directory trees.
PLEASE NOTE '%CD:\=\/%' makes reference to a MS-WINDOWS environment string. So this file has to be generated from a batch file (i.e. with ECHO XXX»file.sed) in order to put the value of the environment string inside the script.
#Line not ending in ":\n" => get filename at char 63. /:.$/!{; s/^.\{62\}/get /; #delete "get ." and "get .." /get \.\{1,2\}.$/d; }; #Line ending in ":\n" => this is a directory name. /:.$/{; s/:.$//; #Hold a copy h; #Insert "cd " at start. Delete spurious "." (or replace with home directory name). s/^/cd /; s/cd \./cd /g; #Print line and work on second copy p; g; #Insert "!mkdir" and current dir at start. (Replace \ with \\). Reverse slashes. s/^/!mkdir %CD:\=\\%\\/g; s!/!\\!g; s/\\[.]\\/\\/g; #Hold another copy. h; #Print and return to copy p; g; #Replace !mkdir with lcd. s/^!mkdir /lcd /; }; #Delete empty lines (I use this since I cannot search for "^\n$"). /^[^0-9A-Za-z]$/d;
Example of usage (for ms-dos users with sed installed):
type mdir_file |sed -e "/:.$/!{;s/^.\{62\}/get /;/get \.\{1,2\}.$/d;};/:.$/{;s/:.$//;h;s/^/cd /;s/cd \./cd /g;p;g;s/^/!mkdir %CD:\=\\%\\/g;s!/!\\!g;s/\\[.]\\/\\/g;h;p;g;s/^!mkdir /lcd /;};/^[^0-9A-Za-z]$/d" >>text_file_to_paste_inside_ftp_client