1

I need to write a WinSCP script or batch file that will download the contents of a remote SFTP folder, delete contents and then upload to a mapped network folder. I know how to write the login part of the script. But I am confused as to what the specific command line should look like. From what I've read the command script to download and delete the file is something like this:

get -delete -transfer=binary *

The part that I'm not getting is the upload to the network folder command. I understand put is the WinSCP upload command operator. But how do I use it in conjunction with the network folder location files should be uploaded to? Also, can this be scripted out in a batch file or do the batch file and script need to be written separately? Thanks!

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
jason_je_bum
  • 45
  • 1
  • 5

1 Answers1

1

An "upload" to a mapped network folder is not a job for WinSCP. A mapped network folder behaves as a local drive. A plain Windows copy command will do. So first do your WinSCP download and then copy (it's not really called an upload) the files to the network drive.

winscp /ini=nul /command ^
    "open sftp://user:password@example.com/" ^
    "get -delete /sftp/path/* c:\local\drive\path\" ^
    "exit"

copy c:\local\drive\path\* n:\mapped\network\drive\path\

Though, if you do not need the files locally, you can have WinSCP download the files from the SFTP folder directly to the mapped network drive:

winscp /ini=nul /command ^
    "open sftp://user:password@example.com/" ^
    "get -delete /sftp/path/* n:\mapped\network\drive\path\" ^
    "exit"
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • You are correct, as always. I should've been more clear. Winscp (and script) will be running on the server that the files will be downloaded to and that drive is network mapped. – jason_je_bum Feb 25 '21 at 20:55