46

I am using PSCP to upload some files from Windows to Linux. I can do it fine just uploading one file at a time. But I have some very large directories and I want to upload an entire directory at once.

I have tried:

pscp -i C:\sitedeploy\abt-keypair.ppk includes\* root@mysite.com:/usr/local/tomcat/webapps/ROOT/includes/*

Throws error: "pscp: remote filespec /usr/local/tomcat/webapps/ROOT/includes/*: not a directory"

and

pscp -i C:\sitedeploy\abt-keypair.ppk includes\ root@mysite.com:/usr/local/tomcat/webapps/ROOT/includes/

Throws error: "scp: includes: not a regular file"

and

pscp -i C:\sitedeploy\abt-keypair.ppk includes root@mysite.com:/usr/local/tomcat/webapps/ROOT/includes

Throws error: "scp: includes: not a regular file"

Peter Mortensen
  • 2,319
  • 5
  • 23
  • 24
Mechlar
  • 607
  • 1
  • 7
  • 10

4 Answers4

47

Two problems: First, the * does not go on the destination side. Second, -r is for copying an entire directory and subdirectories.

pscp -i C:\sitedeploy\abt-keypair.ppk includes\* root@mysite.com:/usr/local/tomcat/webapps/ROOT/includes/

Will copy all of the files in the local includes\ directory to the .../includes/ directory on the server.

pscp -r -i C:\sitedeploy\abt-keypair.ppk includes\ root@mysite.com:/usr/local/tomcat/webapps/ROOT/

Will copy the includes\ directory itself, including all files and subdirectories, to the .../ROOT/ directory on the server (where the contents of the local directory would merge with any existing .../ROOT/includes/ directory.

DerfK
  • 19,313
  • 2
  • 35
  • 51
8

Disclaimer:

You don't need to use -i for this. It's for private key file authentication. Just use -r to copy the source files recursively.

You might want a drag and drop method since you're using Windows. You can - for example - use WINSCP client.

Peter Mortensen
  • 2,319
  • 5
  • 23
  • 24
6

If you want to copy a directory and its contents you don't need to provide a file specification for the destination. Just use the directory name, for example.

pscp  -i C:\sitedeploy\abt-keypair.ppk includes\* root@mysite.com:/usr/local/tomcat/webapps/ROOT/includes/

If you want to copy the directory and everything below it then you can use -r:

pscp -r -i C:\sitedeploy\abt-keypair.ppk includes\ root@mysite.com:/usr/local/tomcat/webapps/ROOT/includes/
Peter Mortensen
  • 2,319
  • 5
  • 23
  • 24
user9517
  • 114,104
  • 20
  • 206
  • 289
0

If you want to copy the folder itself with everything under it, you must use a command as below:

pscp -r -i C:\PrivateKeys\MyPrivateKey.ppk C:\FOLDER1 <username>@<server_id>:/home/<username>/

But notice there is no slash at the end of folder path "C:\FOLDER"; if you use it with an ending slash like "C:\FOLDER1\" it doesn't copy the folder itself, but only copies everything under the folder.

Glorfindel
  • 1,213
  • 3
  • 15
  • 22
Bulent Balci
  • 101
  • 1