Translate into your own language

Monday, February 16, 2026

PostgreSQL - File transfer from local to remote and vice-verca

 

Secure File Transfer Between Windows and Linux Using SCP

Overview

This document explains how to securely transfer files between Windows and Linux servers using SCP (Secure Copy Protocol). It includes examples for downloading files from a Linux server to a Windows machine and uploading files from Windows to Linux. All server names, database names, schema names, and table names are kept generic for reuse across environments.

 

SCP uses SSH for secure file transfer and is commonly used by database administrators for moving logs, reports, backups, and configuration files.

Prerequisites

• SSH access to the Linux server

• SCP available on Windows (Git Bash, PowerShell with OpenSSH, or WSL)

• Proper file permissions on the Linux server

• Network connectivity between systems

Download File from Linux Server to Windows

Example command:

 

scp user@linux-server:/path/to/file /c/Users/youruser/Downloads/

 

Explanation:

This command copies a file from the Linux server to the Windows Downloads directory.

Upload File from Windows to Linux Server

Example command:

 

scp /c/Users/youruser/Downloads/file.zip user@linux-server:/home/user

 

Explanation:

This uploads a file from the Windows machine to the Linux server home directory.

Common Use Case — Copy Logs with Permission Restrictions

In many environments, log files are owned by root or restricted users. In such cases, first copy the file to a user-accessible directory before downloading.

Step 1: Copy File to Home Directory (Linux Server)

As root or sudo user:

 sudo su -

cp /var/log/application/logfile.log /home/user/

chown user:user /home/user/logfile.log

 

Explanation:

This ensures the file has proper permissions for SCP transfer.

Step 2: Download File from Windows

From Windows (Git Bash or PowerShell):

 

scp user@linux-server:/home/user/logfile.log /c/Users/youruser/Downloads/

 

Explanation:

This safely downloads the file to the Windows machine.

Upload Configuration or Application Files to Linux

Example:

 

scp /c/Users/youruser/Downloads/config.properties user@linux-server:/home/user

 

Explanation:

This is commonly used for transferring configuration files or application packages.

Copy Multiple Files Using Wildcards

Example:

 

scp user@linux-server:/home/user/logfile* /c/Users/youruser/Downloads/

 

Explanation:

Wildcards allow transferring multiple matching files in one command.

Best Practices

• Use home directory as a staging area for transfers

• Verify file permissions before copying

• Use SSH keys instead of passwords when possible

• Compress large files before transfer

• Validate file size after transfer

Troubleshooting

Permission Denied:

Ensure file ownership and read permissions are correct.

 

Connection Timeout:

Verify network connectivity and firewall rules.

 

File Not Found:

Check the correct file path on the server.

Conclusion

SCP provides a simple and secure way to transfer files between systems. Following proper permission handling and staging practices ensures smooth and reliable transfers in production environments.

No comments:

Post a Comment