Skip to content

CopyToVFS()

ts
CopyToVFS(localFile: string, targetVfs: VirtualFileSystem, targetVfsFilePath: string): respBase;

Copies a file, identified by its root-based POSIX path inside the caller VFS, to a different VFS (object of type VirtualFileSystem) in the specified target path of the receiving VFS.

Parameters

ParameterTypeExplanation
localFilestringThe fully qualified, root-based POSIX path (in the caller VFS) of the file you wish to copy
targetVfsVirtualFileSystemThe VFS you wish to copy the file to; this must be different from the caller-VFS (origin)
targetVfsFilePathstringThe fully qualified path, relative to the recipient-VFS root, you wish the file to have in the VFS after import

Example

ts
// Make sure we have a caller (origin) VFS to copy the file from
var originVfs = GetCurrentVFS();
if (originVfs == null) {
    Exit(1);
}
// Then let's see if we can create the destination VFS pointing to S3
var recipientVfs = new VirtualFS(
      VfsTypeS3, 
      "s3://myS3bucket", 
      "{\"accessKey\":\"AKIA...\",\"secretKey\":\"...\"}"
);
if (recipientVfs != null) {
    var resp = originVfs.CopyToVFS("/data/file.txt", recipientVfs, "/backup/file.txt");
    if (resp.Ok()) {
        Log("File copied to S3");
    } else {
        Log("Error: " + resp.ErrorMsg());
    }
}