Running CFDDFC with the Azure Console
- Launch a Virtual Machine
- Connect to a Virtual Machine
- Using OpenFOAM on a Virtual Machine
- Data Transfer to a Virtual Machine
- Connect with the Remote Desktop
Secure copy protocol
Data can be transferred to and from a virtual machine (VM) using the secure copy protocol (SCP), based on SSH described previously. SSH with a key pair provides both encryption for data transfer and authentication of the user. The OpenSSH secure copy application “
scp” enables file transfer from the command line on Linux, MacOS and Windows 10.
Copying files with scp
The basic command copies file(s) from a source location to a target location:
scp <source> <target>
A source or target is on the local machine is simply specified by the directory path and file name, e.g. “
/home/john/foo.txt”. This example uses the full directory path, but a relative path can be used and the path can be omitted if the file is in the current directory.
The source or target on the remote VM is specified by
<user>@<host>:<file/dir>. For example, for user
ubuntu, at IP address
18.104.22.168, a target home directory is specified as “
email@example.com:~/”. The command to copy a
foo.txt file to this location is:
scp foo.txt firstname.lastname@example.org:~/
This command will work if the relevant private key is added to the the SSH agent. Otherwise, the key file would need to be supplied with the command using the
-i option, e.g.
scp -i ~/.ssh/awskey.pem foo.txt email@example.com:~/
Copying a file named
foo.txt from the home directory on the VM back to the local machine would be (note the target “dot”):
scp -i ~/.ssh/awskey.pem firstname.lastname@example.org:~/foo.txt .
A directory can be copied with
scp using the
-r option. For example, imagine we want to copy the
pitzDaily case directory in our current directory to the VM. The case can be copied with the following command — assuming the key is added to the agent, otherwise include the
-i <keyfile> option.
scp -r pitzDaily email@example.com:~/
scp can be used for copying directories is likely that users will want to synchronize files on local and remote machines. The
rsync application is better suited to synchronization of files and uses
ssh as the default shell for connecting to the remote VM. Assuming the key is added to the agent, the command to copy the
pitzDaily case is:
rsync -av pitzDaily firstname.lastname@example.org:~/
-a option means “archive mode” which allows copying of directories while maintaining file timestamps, permissions and links. The
-v option writes more output, reporting on the copied files. Without the agent, the key file can be supplied as follows:
rsync -av -e "ssh -i ~/.ssh/awskey.pem" pitzDaily email@example.com:~/
Note: be careful about trailing slashes / on the ends of directory names which changes the meaning of the rsync command. The files can be synchronized from the remote VM to the local machine. It can be tested by creating an empty file
foo.txt in the
pitzDaily case on the remote machine by running the
touch command remotely:
ssh firstname.lastname@example.org "touch pitzDaily/foo.txt"
pitzDaily case is then synchronized back to the local machine, noting that only the
foo.txt file is copied.
rsync -av email@example.com:~/pitzDaily .
The user can also ensure that files are deleted at the target which do not exist at the source using the
--delete option. This can be tested by deleting the
foo.txt file created previously on the remote VM.
ssh firstname.lastname@example.org "rm pitzDaily/foo.txt"
The file is then deleted on the local machine by running the following command:
rsync -av --delete email@example.com:~/pitzDaily .
-z option can be included “
rsync -avz…” which compresses file data for transfer, which helps to reduce file transfer costs. Alternatively users can reduce the need for compressing data for transfer by writing data in binary format using the following option in the case
or compress the ASCII data with the options:
writeFormat ascii; writeCompression on;
Users may wish to synchronize case directories into the “
run” directory on the remote VM, denoted by the OpenFOAM environment variable
$FOAM_RUN. To do this, the environment variable should be “backquoted” to prevent its expansion on the local machine, ensuring it is correctly expanded on the remote VM, e.g.:
rsync -av pitzDaily firstname.lastname@example.org:\$FOAM_RUN/
run directory must be created on the remote VM, which occurs with the first SSH login into it.