Ascp File Manipulation Examples

Below are examples of using the ascp command to manipulate files. In each example, the client is the local computer and the server is the remote computer.

  • Upload a directory

    Upload the directory /data/ to the server at 10.0.0.1, and place it in the /storage/ directory on the server:

    # ascp /src/data/  root@10.0.0.1:/storage/ 
  • Upload only the contents of a directory (not the directory itself) by using the --src-base option:

    Upload only the contents of /data/ to the /storage/ directory at the destination. Strip the /src/data/ portion of the source path and preserve the remainder of the file structure at the destination:

    # ascp --src-base=/src/data/ /src/data/ root@10.0.0.1:/storage/ 
  • Upload a directory and its contents to a new directory by using the -d opton.

    Upload the /data/ directory to the server and if it doesn't already exist, create the new folder /storage2/ to contain it, resulting in /storage2/data/ at the destination.

    # ascp -d /src/data/ root@10.0.0.1:/storage2/ 
  • Upload the contents of a directory, but not the directory itself, by using the --src-base option:

    Upload all folders and files in the /clips/out/ folder, but not the out/ folder itself, to the /in/ folder at the destination.

    # ascp -d --src-base=/clips/out/ /clips/out/ root@10.0.0.1:/in/  

    Result: The source folders and their content appear in the in directory at the destination:

    Source
    /clips/out/file1              
    /clips/out/folderA/file2
    /clips/out/folderB/file3

    Destination (docroot)
    /in/file1
    /in/folderA/file2
    /in/folderB/file3

    Destination without --src-base
    /in/out/file1
    /in/out/folderA/file2
    /in/out/folderB/file3

    Without --src-base, the example command transfers not only the contents of the out/ folder, but the folder itself.

  • Upload only the contents of a file and a directory to a new directory by using --src-base

    Upload a file, /monday/file1, and a directory, /tuesday/*, to the /storage/ directory on the server, while stripping the srcbase path and preserving the rest of the file structure. The content is saved as /storage/monday/file1and /storage/tuesday/* on the 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 by using --src-base

    Download a file, /monday/file1, and a directory, /tuesday/*, from the server, while stripping the srcbase path and preserving the rest of the file structure. The content is saved as /data/monday/file1 and /data/tuesday/* on the client.

    # ascp --src-base=/storage/content root@10.0.0.1:/storage/content/monday/file1 root@10.0.0.1:/storage/content/tuesday/ /data 
  • Move the source file on the client after it is uploaded to the server by using --move-after-transfer

    Uploadfile0012 to Pat's docroot on the server at 10.0.0.1, and move (not copy) the file from C:/Users/Pat/srcdir/ to C:/Users/Pat/Archive on the client.

    # ascp --move-after-transfer=C:/Users/Pat/Archive C:/Users/Pat/srcdir/file0012 Pat@10.0.0.1:/
  • Move the source file on the server after it is downloaded to the client by using --move-after-transfer

    Download srcdir from the server to C:/Users/Pat on the client, and move (not copy) srcdir to the archive directory /Archive on the server.

    # ascp --move-after-transfer=Archive Pat@10.0.0.1:/srcdir C:/Users/Pat
  • Move the source file on the client after it is uploaded to the server and preserve the file structure one level above it by using --src-base and --move-after-transfer

    Upload file0012 to Pat's docroot on the server at 10.0.0.1, and save it as /srcdir/file0012 (stripped of C:/Users/Pat). Also move file0012 from C:/Users/Pat/srcdir/ to C:/Users/Pat/Archive on the client, where it is saved as C:/Users/Pat/Archive/srcdir/file0012.

    # ascp --src-base=C:/Users/Pat --move-after-transfer=C:/Users/Pat/Archive C:/Users/Pat/srcdir/file0012 Pat@10.0.0.1:/
  • Delete a local directory once it is uploaded to the remote server by using --remove-after-transfer and --remove-empty-directories

    Upload /content/ to the server, then delete its contents (excluding partial files) and any empty directories on the client.

    # 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 by using --src-base, --remove-after-transfer, and --remove-empty-directories

    Upload /content/ to the server, while stripping the srcbase path and preserving the rest of the file structure. The content is saved as /storage/* on the server. On the client, the contents of /content/, including empty directories but excluding partial files, are deleted.

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