ascp command line tool allows you to make transfers via a terminal/command prompt as well as in your scripts.
When transferring a folder to or from a remote directory, the default behavior is that the transferred folder is created if it does not exist on the destination.
Consider an example where you have a folder named
my_Videos on your local machine with the following content:
Say you want to transfer the contents of
my_Videos to a folder named
received_Videos on a remote machine example_host.com. A new folder will be created on example_host.com at the destination if it does not already exist. The command for transferring with
ascp is the following:
ascp /path/to/my_Videos user@example_host.com:/path/to/received_Videos
This can become problematic if a folder
received_Videos does exist on the remote machine prior to the transfer. In this case, running the above command will cause a folder named
my_Videos to be created within the existing
To fix the issue so that only the content of
my_Videos is transferred to
received_Videos, you must use the
--src-base option in your
General use of --src-base
The syntax you use for an
ascp command with
--src-base is the following:
ascp --src-base=prefix [user@source_machine:]/path/to/folder [user@destination_machine:]/path/to/folder
The prefix value should be replaced with the path that you want stripped off the files being transferred. The
--src-base option works for both files being uploaded to or downloaded from a remote source.
--src-base option allows you to strip off a portion of the paths of the source files being transferred.
Continuing with the example of the Description section, this means that we must strip the path of the files up to the folder
my_Videos, so that only the files within
my_Videos are transferred.
The command we would use to do this is the following:
ascp --src-base=/path/to/my_Videos/ /path/to/my_Videos user@example_host.com:/path/to/received_Videos
In this way, for the file
my_Videos which has the full path of
/path/to/my_Videos/vid1.mov, we will only be transferring
vid1.mov to the destination.
Now we have the content that we want in the way we want it at the remote destination: