Ascp File Manipulation Examples

Examples of manipulating files using the ascp command.

This topic demonstrates file manipulation using the ascp command with the following examples:

  1. Upload directory contents to remote computer

    Upload the "/content/" directory to the remote server.

    $ ascp /data/content/  root@10.0.0.1:/storage/ 

    Result => /storage/content/*

    Upload the "/content/" directory to the remote server, but strip the srcbase path and preserve the rest of the file structure.

    $ ascp --src-base=/data/content /data/content/ root@10.0.0.1:/storage 

    Result => /storage/*

  2. Upload directory contents to remote computer and create the destination folder if it does not already exist

    Upload the "/content/" directory to the remote server and create the "/storage2" folder since it does not exist.

    $ ascp -d /data/content/  root@10.0.0.1:/storage2/ 

    Result => /storage2/content/*

  3. Download directory contents from remote computer

    Download the "/content/" directory to the remote server, but strip the srcbase path and preserve the rest of the file structure.

    $ ascp --src-base =/storage/content root@10.0.0.1:/storage/content/ /data 

    Result => /data/*

  4. Upload selected files and directories to a remote computer and preserve directory structure

    Upload the selected file and directory to the remote server, but strip the srcbase path and preserve the rest of the file structure.

    $ ascp --src-base=/data/content /data/content/monday/file1 /data/content/tuesday/ root@10.0.0.1:/storage 

    Results => /storage/monday/file1 AND /storage/tuesday/*

  5. Download selected files and directories from a remote computer and preserve directory structure

    Download the selected file and directory from the remote server, but strip the srcbase path and preserve the rest of the file structure.

    $ ascp --src-base=/storage/content root@10.0.0.1:/storage/content/monday/file1 root@10.0.0.1:/storage/content/tuesday/ /data 

    Results => /data/monday/file1 AND /data/tuesday/*

  6. Remove source files from the local computer after transferring them to the remote computer

    Remove the "/content/" directory of the local computer after the contents (excluding partial files) have been transferred to the remote computer.

    $ ascp -k2 -E "*.partial" --remove-after-transfer --remove-empty-directories /data/content root@10.0.0.1:/storage

    Result => /storage/content/*

    Remove the "/content/" directory of the local computer after the contents (excluding partial files) have been transferred to the remote computer. Strip the srcbase path and preserve the rest of the file structure

    $ ascp -k2 -E "*.partial" --src-base=/data/content --remove-after-transfer --remove-empty-directories /data/content root@10.0.0.1:/storage 

    Result => /storage/*

    Important: For version 2.7.1, the "-d" option is required when specifying the "--src-base" option if the target directory does not exist. As of version 2.7.3+, this constraint has been removed.