How to Transfer Entire Directories with PSCP: Windows to Linux File Upload Guide


2 views

When working with PSCP (PuTTY Secure Copy Protocol), many developers encounter difficulties when attempting to transfer entire directories from Windows to Linux systems. The error messages you're seeing are common pain points that stem from how PSCP handles directory transfers differently from single file operations.

The key to successful directory transfer lies in using the -r (recursive) flag. Here's the correct command structure:

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

1. Trailing Slashes Matter
Notice the absence of a trailing slash after "includes" - this tells PSCP to copy the entire directory structure.

2. Destination Path Handling
The destination should be the parent directory (/usr/local/tomcat/webapps/ROOT/) rather than trying to specify the target directory name.

Preserving File Permissions

pscp -r -p -i private_key.ppk source_dir user@host:/target/path/

Excluding Specific Files
While PSCP doesn't support native exclude patterns, you can combine with robocopy on Windows:

robocopy source_dir temp_dir /XF *.tmp /S
pscp -r -i key.ppk temp_dir user@host:/target/

For very large directories, consider compressing first:

# Windows
powershell Compress-Archive -Path includes -DestinationPath includes.zip

# Transfer
pscp -i key.ppk includes.zip user@host:/tmp/

# On Linux server
ssh user@host "unzip /tmp/includes.zip -d /target/path/"
  • Use -batch to suppress interactive prompts
  • Add -q for quiet mode on large transfers
  • Consider -l to limit bandwidth during business hours

When working with PSCP (PuTTY SCP client), many developers encounter difficulties when trying to transfer entire directories from Windows to Linux systems. The typical error messages you might see include:

pscp: remote filespec /path/to/destination/*: not a directory
scp: source_folder: not a regular file

Unlike regular SCP, PSCP requires a specific approach for recursive directory transfers. Here's the proper command structure:

pscp -scp -r -i C:\path\to\privatekey.ppk C:\local\path\to\folder\* username@remotehost:/remote/path/

The -r flag is crucial as it enables recursive copying of directories. Note that you must include the trailing asterisk (*) after the source folder path.

For your specific case mentioned in the question, the working command would be:

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

Key points to remember:

  • Always use forward slashes for the remote path (Linux style)
  • The destination directory must already exist on the remote server
  • Never include wildcards in the destination path

If you frequently need to transfer directories, consider using WinSCP which has a more intuitive GUI and better support for recursive transfers:

winscp.com /command "open sftp://username:password@hostname -privatekey=key.ppk" "put -transfer=binary -preservetime -nopermissions C:\local\folder\* /remote/path/" "exit"

For large directories, consider these optimizations:

pscp -scp -r -l 5000 -batch -p -q -i key.ppk source\* user@host:/path/

Where:

  • -l 5000 limits bandwidth to 5000 Kbps
  • -batch prevents interactive prompts
  • -p preserves file timestamps
  • -q enables quiet mode

After transfer, verify files using SSH:

ssh -i key.ppk user@host "ls -lh /remote/path/"