With WinSCP 5.2 I wanted to put multiple files with a file extension .pgp on an SFTP site. When I tested my original command line (see below) and it only placed the first *.pgp alphabetical file (D:\a.csv.pgp) on the SFTP site. I tried specifying *.PGP and *.pgp without any changes - only one file (D:\a.csv.pgp) would be copied each time. I got it to work for all files only if I specified a put command for each .pgp file. Any ideas on how to put all *.pgp on the SFTP site?

Original Command Line - Does Not Work
d:\winscp\winscp /command "option echo off" "option batch on" "option confirm off" "open sftp" "put D:\*.pgp" "close" "exit"

d:\winscp\winscp /command "option echo off" "option batch on" "option confirm off" "open sftp" "put D:\a.csv.pgp" "put D:\b.csv.pgp" "put D:\c.csv.pgp" "put D:\d.csv.pgp" "put D:\e.csv.pgp" "put D:\f.csv.pgp" "put D:\g.csv.pgp" "put D:\h.csv.pgp" "put D:\i.csv.pgp" "close" "exit"


You seem to be using SFTP mode rather than SCP mode

Try mput *.pgp (a guess based on FTP commands)

The manual says wildcards should work

put <file> [ [ <file2> ... ] <directory>/[ <newname> ] ]
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.

put *.html *.png /home/martin/backup/*.bak

You MUST put the target directory as the last item in the quoted command.

d:\winscp\winscp /command "option echo off" "option batch on" "option confirm off" "open sftp" "put D:\*.pgp ""C:\Documents and Settings\newtowinscp\Documents\Backups""" "close" "exit"

  • As OP has only single parameter in his put D:\*.pgp command, it's not necessary to add the target directory as the last parameter. Moreover in your example, you use a Windows path as a target directory, what won't work (even if the server is Windows server, with SFTP, paths have to use forward slash as separators). – Martin Prikryl Jun 12 '14 at 15:20

If you are running this from a script, you can just create a loop. You would take all of the *.pgp files and iterate through the list. You would actually upload the files individually; I don't believe that SFTP/SCP at the protocol level moves multiple files at once anyway, so I don't think this should affect performance, it would probably make error handling easier as well.

I believe there is a way to do this with the pure native command line, but in my backup scripts (I do the inverse, I pull files down from my SFTP site) I use this program (forfiles) from Microsoft: http://technet.microsoft.com/en-us/library/cc753551(WS.10).aspx . I will let you read through the examples there on how to use it most effectively for your needs. Basically, you will use a wildcard for filename and then run your upload command for each instance.


There's nothing wrong with your first command (with put D:\*.pgp).

As you claim that only a single file is uploaded, it's likely because some error occurs, what prevent the script from continuing with other files. It must be an error in operation that following the actual upload (as that succeeds), such as updating uploaded file timestamp or permissions.

Such as this error: Upload of file .. was successful, but error occurred while setting the permissions and/or timestamp. If the problem persists, turn off setting permissions or preserving timestamp. Alternatively you can turn on 'Ignore permission errors' option..

You should clearly see, what is actually wrong in the script output or session log file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.