cp command

Duplicates one or more remote files.

Advertisement

Syntax

cp <file> [ <file2> ... ] [ <directory>/ ][ <newname> ]

Remarks

Destination directory or newname or both must be specified. Destination directory must end with slash. Operation mask can be used instead of new name. Filename can be replaced with wildcard to select multiple files.

Effective options: failonnomatch

XML log element: cp

Examples

cp index.html backup/
cp index.html *.bak
cp index.html public_html/about.*
cp public_html/index.html public_html/about.html /home/martin/*.bak

Advertisement

Converting to .NET Assembly

When converting script to .NET Assembly, map cp command to Session.DuplicateFile method.

Parameters mapping: Command parameter file maps to method parameter sourcePath. When multiple source file parameters are used, you need to call Session.DuplicateFile multiple times. Command parameter directory/newname maps to method parameter targetPath. You have to convert relative paths to absolute paths.

For example, following script snippet:

cd /home/martinp
cp public_html/index.html public_html/about.html *.bak

maps to following PowerShell code:

$session.DuplicateFile("/home/martinp/public_html/index.html", "/home/martinp/*.bak")
$session.DuplicateFile("/home/martinp/public_html/about.html", "/home/martinp/*.bak")

Last modified: by martin