This is an old revision of the document!

get

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

get <file> [ [ <file2> ... ] <directory>\[ <newname> ] ]

Advertisement

Downloads one or more files from remote directory to local directory. If only one parameter is specified downloads the file to local working directory. If more parameters are specified, all except the last one specify set of files to download. The last parameter specifies target local directory and optionally operation mask to store file(s) under different name. Destination directory must end with backslash. Filename can be replaced with wildcard to select multiple files. To download more files to current working directory use .\ as the last parameter.

See also synchronize, if you need to transfer modified or non-existing files only.

Aliases: recv, mget

Switches:

Switch Description
-delete Delete source remote file(s) after transfer.
-resume Automatically resume transfer if possible.1 (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
-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

Effective options: confirm, reconnecttime

XML log elements: download, rm (with -delete)

Examples

get index.html
get -delete index.html about.html .\
get index.html about.html d:\www\
get public_html/index.html d:\www\about.*
get *.html *.png d:\www\*.bak
get -filemask=*.html -resumesupport=on *

Converting to .NET Assembly

When converting script to .NET Assembly, map get command to Session.GetFiles method.

Parameters mapping: Command parameter file maps to method parameter remotePath. When multiple source file parameters are used, you need to call Session.GetFiles multiple times. Command parameter directory\newname maps to method parameter localPath. 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
-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:\
...
get -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
$resumeSupport = New-Object TransferResumeSupport 
$resumeSupport.State = [WinSCP.TransferResumeSupportState]::Off
$transferOptions.ResumeSupport = $resumeSupport
# Absolute paths + $True for -delete + Two calls for two source parameters
$transferResult = $session.GetFiles("/home/martinp/*.txt", "d:\web\", $True, $transferOptions)
$transferResult = $session.GetFiles("/home/martinp/*.xml", "d:\web\", $True, $transferOptions)
# Throw on any error to emulate "option batch abort"
$transferResult.Check()
  1. To be used for single file transfers only. It does not skip transfer of fully transferred files.Back

Last modified: by martin