This is an old revision of the document!
get command
Downloads one or more files from remote directory to local directory.
Advertisement
Syntax
get <file> [ [ <file2> ... ] <directory>\[ <newname> ] ]
Remarks
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. Filename can be replaced with wildcard to select multiple files. To download all files in a directory, use mask *
.
The last parameter specifies target local directory and optionally operation mask to store file(s) under different name. Target directory must end with backslash. To download more files to current working directory use .\
as the last parameter.
With the /stdout
command-line switch, -
can be used as a target to stream the contents of downloaded file(s) to the standard output of winscp.com
. Streaming is supported with the SFTP and FTP (beta version only) protocols only.
When specific file name is used, command fails when the file does not exist. When wildcard is used, command succeeds, without doing anything, if the wildcard does not match any file, by default (you can change this using option failonnomatch on
command).
You can have WinSCP generate a code template for get
for you.
See also synchronize
, if you need to transfer modified or non-existing files only.
Aliases: recv
, mget
Advertisement
Switches:
Switch | Description |
---|---|
-delete |
Delete source remote file(s) after a successful transfer. |
-latest |
Download the latest file from the files selected by the file , file2 … parameters (typically file masks) only. |
-resume |
Automatically resume transfer if possible.1 SFTP and FTP protocols only. Cannot be combined with -append . Has no effect when streaming (- target). |
-append |
Append source file to the end of target file. SFTP protocol only. Cannot be combined with -resume . Has no effect when streaming (- target). |
-preservetime |
Preserve timestamp. |
-nopreservetime |
Do not preserve timestamp. |
-speed=<kbps> |
Limit transfer speed (in KB/s). |
-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. |
-neweronly |
Transfer new and updated files only. See also synchronize command. |
-rawtransfersettings setting1=value1 setting2=value2 … |
Allows configuring any transfer settings using raw format as in an INI file. E.g. to enable preserving of directory timestamps, use -rawtransfersettings PreserveTimeDirs=1 . The switch should come only after other parameters. |
Effective options: confirm
, reconnecttime
, failonnomatch
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
Advertisement
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 in PowerShell) for method parameter remove . |
-latest |
See Downloading the most recent file. |
-resume -append -preservetime -nopreservetime -transfer -filemask -resumesupport -speed=<kbps> |
Converting transfer settings scripting switches to .NET assembly class TransferSettings . |
-neweronly |
Not supported. Use Session.SynchronizeDirectories instead. |
To emulate the (default) option batch abort
mode, call TransferOperationResult.Check
on method’s result. See also Capturing results of operations.
For example, following script snippet:
cd /home/martinp lcd d:\ ... get -delete -filemask=*>1M -resumesupport=off *.txt *.xml web\
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 the (default) "option batch abort" mode $session.GetFiles("/home/martinp/*.txt", "d:\web\", $True, $transferOptions).Check() $session.GetFiles("/home/martinp/*.xml", "d:\web\", $True, $transferOptions).Check()
- Applies for individual files transfers only. It does not skip transfer of fully transferred files. For that, combine the switch with
-neweronly
.Back
Advertisement