IFS=$'\n' src_dirs=($(find $SRC_DIRECTORY | tail -n +2 | xargs -n 1 dirname | sort | uniq)) To solve the use case, we must traverse through the directory to generate a set of FTP commands to replicate the entire directory structure from the local to the remote FTP server.įirst, let’s create the copy.sh Bash script and initialize the src_dirs and files variables as an array of absolute paths for the source directories and files, respectively: $ cat copy.sh In the next section, we’ll develop a script to solve this use case, as there’s no direct way to copy a complete directory recursively to an FTP server. However, it couldn’t copy the my_sub_dir subdirectory and the files under it. Great! We got some success this time, wherein my_dir/f1.txt and my_dir/f2.txt files were transferred. Local: my_dir/my_sub_dir remote: my_dir/my_sub_dir Next, let’s also see if we can use the * wildcard in the file path to copy files after creating the my_dir directory manually: ftp> mkdir my_dir mput my_dir/* We can see that our attempt failed because the mput command supports only files, not directories. Now, let’s see if we can use the mput command to copy all the files under the my_dir directory to the FTP server: ftp> mput my_dir First, let’s start by looking into the directory structure in a tree format using the exa command: $ exa -tree my_dir
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |