Ascp File Manipulation Examples

Below are examples of using the ascp command to manipulate files.

  • Upload a directory

    Upload a directory, /content/, to the remote server 10.0.0.1. The following produces /storage/content/* on the remote server:

    # ascp /data/content/  root@10.0.0.1:/storage/ 
  • Upload only the contents of a directory

    Upload only the contents of /content/ to the remote server, stripping the srcbase path and preserving the rest of the file structure. The following produces /storage/* on the remote server:

    # ascp --src-base=/data/content /data/content/ root@10.0.0.1:/storage 
  • Upload a directory to a new directory

    Upload /content/ to the remote server and create a new folder, /storage2, to contain it. The following produces /storage2/content/* on the remote server:

    # ascp -d /data/content/  root@10.0.0.1:/storage2/ 
  • Download only the contents of a directory

    Download the contents of /storage/content/ from the remote server, while stripping the srcbase path and preserving the rest of the file structure. The following produces /data/* on the local machine:

    # ascp --src-base =/storage/content root@10.0.0.1:/storage/content/ /data 
  • Upload only the contents of a file and a directory to a new directory

    Upload a file, /monday/file1and a directory, /tuesday/*, to the /storage directory on the remote server, while stripping the srcbase path and preserving the rest of the file structure. The following produces /storage/monday/file1and /storage/tuesday/* on the remote server:

    # ascp --src-base=/data/content /data/content/monday/file1 /data/content/tuesday/ root@10.0.0.1:/storage 
  • Download only the contents of a file and a directory to a new directory

    Download a file, /monday/file1, and a directory, /tuesday/*, from the remote server, while stripping the srcbase path and preserving the rest of the file structure. The following produces /data/monday/file1 and /data/tuesday/* on the local machine:

    # ascp --src-base=/storage/content root@10.0.0.1:/storage/content/monday/file1 root@10.0.0.1:/storage/content/tuesday/ /data 
  • Delete a local directory once it has been transferred to the remote server

    Remove /content/ from the local machine after its contents (excluding partial files) have been transferred to the remote server. The following produces /storage/content/* on the remote server:

    # ascp -k2 -E "*.partial" --remove-after-transfer --remove-empty-directories /data/content root@10.0.0.1:/storage
  • Delete a local directory once its contents have been transferred to the remote server

    Remove /content/ from the local machine after the contents (excluding partial files) have been transferred to the remote server, while stripping the srcbase path and preserving the rest of the file structure. The following produces /storage/* on the remote server:

    # ascp -k2 -E "*.partial" --src-base=/data/content --remove-after-transfer --remove-empty-directories /data/content root@10.0.0.1:/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.