This is an old revision of the document!

put

Uploads one or more files from local directory to remote directory.

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

Advertisement

If only one parameter is specified uploads the file to remote working directory. If more parameters are specified, all except the last one specify set of files to upload. The last parameter specifies target remote directory and optionally operation mask to store file(s) under different name. Destination directory must end with slash. Filename can be replaced with Windows wildcard1 to select multiple files. To upload more files to current working directory use ./ as the last parameter.

See also synchronize, if you need to transfer modified files only.

Switches:

Switch Description
-delete Delete source local file(s) after transfer.
-resume Automatically resume transfer if possible (SFTP and FTP protocols only). Cannot be combined with -append.
-append Append source file to the end of target file (SFTP protocol only). Cannot be combined with -resume.
-preservetime Preserve timestamp
-nopreservetime Do not preserve timestamp
-permissions=<mode> Set permissions (SFTP and SCP protocols only)
-nopermissions Keep default permissions
-speed=<kibps> Limit transfer speed
-transfer=<mode> binary|ascii|automatic
Transfer mode: binary, ascii (text), automatic (by extension).
-filemask=<mask> <mask>[;<mask2>...]
Sets file mask.
-resumesupport= <state> on|off|<threshold>
Configures automatic resume/transfer to temporary filename. This feature is available only in the latest beta release.

Advertisement

Aliases: send, mput

Effective options: confirm, reconnecttime

XML log elements: upload, chmod (with -permissions), touch (with -preservetime)

Examples

put index.html
put -delete index.html about.html ./
put -permissions=644 index.html about.html /home/martin/public_html/
put d:\www\index.html about.*
put *.html *.png /home/martin/backup/*.bak
put -filemask=*.html -resumesupport=on *

Converting to .NET Assembly

When converting script to .NET Assembly, map put command to Session.PutFiles method.

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

Switches mapping:

Switch Mapping
-delete Value true ($True) for method parameter remove.
-resume Not supported.
-append Not supported.
-preservetime
-nopreservetime
-permissions
-nopermissions
-transfer
-filemask
-resumesupport
Converting transfer settings scripting switches to .NET assembly class TransferSettings.
-speed=<kibps> Not supported.

To emulate option batch abort mode, call TransferOperationResult.Check on method’s result. See also Capturing results of operations.

For example, following script snippet

option batch abort
...
cd /home/martinp
lcd d:\
...
put -delete -filemask=*>1M -resumesupport=off *.txt *.xml web/

Advertisement

maps to following PowerShell code

$transferOptions = New-Object WinSCP.TransferOptions
# -filemask=*>1M
$transferOptions.FileMask = "*>1M"
# -resumesupport=off
$transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::Off
# Absolute paths + $True for -delete + Two calls for two source parameters
# + calling Check on result to emulate "option batch abort"
$session.PutFiles("d:\*.txt", "/home/martinp/web/", $True, $transferOptions).Check()
$session.PutFiles("d:\*.xml", "/home/martinp/web/", $True, $transferOptions).Check()
  1. Windows wildcard supports * and ? only. It does not support all the features of file masks.Back

Last modified: by martin