PSFTP - Secure File Transfer Protocol Client

Interactive and scriptable SFTP client for secure file transfers over SSH

What is PSFTP?

PSFTP is a secure file transfer client that implements the SSH File Transfer Protocol (SFTP). It provides both interactive and batch-mode operation for transferring files securely over an SSH connection.

PSFTP is part of the PuTTY suite and offers a command-line interface similar to traditional FTP clients, but with the security of SSH encryption.

Key Features:

  • • Secure file transfer over SSH
  • • Interactive and batch modes
  • • Support for SSH-2 protocol
  • • Public key authentication
  • • Recursive directory transfers
  • • Resume interrupted transfers
  • • Compatible with OpenSSH SFTP servers

Basic Usage

Interactive Mode

psftp username@hostname

With Private Key

psftp -i private_key.ppk username@hostname

Batch Mode with Commands

psftp -batch -b commands.txt username@hostname

Using Saved Session

psftp session_name

SFTP Commands

CommandDescription
lsList remote directory contents
llsList local directory contents
cd directoryChange remote directory
lcd directoryChange local directory
get filenameDownload file from remote
put filenameUpload file to remote
mget patternDownload multiple files
mput patternUpload multiple files
mkdir directoryCreate remote directory
rmdir directoryRemove remote directory
rm filenameDelete remote file
rename old newRename remote file

Command Line Options

OptionDescription
-P portSpecify port number
-l usernameSpecify username
-pw passwordSpecify password
-i keyfileSpecify private key file
-batchDisable interactive prompts
-b batchfileRead commands from file
-bcOutput batch commands
-beDon't stop batch on errors

Batch Mode Examples

Creating a Batch File

Create a text file (e.g., commands.txt) with SFTP commands:

cd /var/www/html
lcd C:\localwebsite
mput *.html
mput *.css
mput *.js
quit

Running Batch Commands

psftp -batch -b commands.txt -i mykey.ppk user@server

Automated Backup Script

@echo off
echo Creating backup directory...
echo mkdir /backup/%date:~10,4%-%date:~4,2%-%date:~7,2% > backup.txt
echo cd /backup/%date:~10,4%-%date:~4,2%-%date:~7,2% >> backup.txt
echo lcd C:\data >> backup.txt
echo mput * >> backup.txt
echo quit >> backup.txt

psftp -batch -b backup.txt -i backup.ppk user@backupserver
del backup.txt

Tips and Best Practices

Use Key Authentication

For automated scripts, always use SSH key authentication instead of passwords for better security.

Error Handling

Use the -be option to continue batch operations even if some commands fail:

psftp -batch -be -b commands.txt user@server

Large File Transfers

For large files, PSFTP automatically handles resume functionality. If a transfer is interrupted, simply restart the same command.

Wildcards

PSFTP supports wildcards in mget and mput commands for transferring multiple files matching a pattern.

PSFTP vs PSCP

PSFTP:

  • • Interactive mode
  • • Directory browsing
  • • Multiple file operations
  • • Resume transfers

PSCP:

  • • Single command transfers
  • • Faster for simple tasks
  • • Better for scripting
;