Interactive and scriptable SFTP client for secure file transfers over SSH
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.
psftp username@hostname
psftp -i private_key.ppk username@hostname
psftp -batch -b commands.txt username@hostname
psftp session_name
Command | Description |
---|---|
ls | List remote directory contents |
lls | List local directory contents |
cd directory | Change remote directory |
lcd directory | Change local directory |
get filename | Download file from remote |
put filename | Upload file to remote |
mget pattern | Download multiple files |
mput pattern | Upload multiple files |
mkdir directory | Create remote directory |
rmdir directory | Remove remote directory |
rm filename | Delete remote file |
rename old new | Rename remote file |
Option | Description |
---|---|
-P port | Specify port number |
-l username | Specify username |
-pw password | Specify password |
-i keyfile | Specify private key file |
-batch | Disable interactive prompts |
-b batchfile | Read commands from file |
-bc | Output batch commands |
-be | Don't stop batch on errors |
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
psftp -batch -b commands.txt -i mykey.ppk user@server
@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
For automated scripts, always use SSH key authentication instead of passwords for better security.
Use the -be option to continue batch operations even if some commands fail:
psftp -batch -be -b commands.txt user@server
For large files, PSFTP automatically handles resume functionality. If a transfer is interrupted, simply restart the same command.
PSFTP supports wildcards in mget and mput commands for transferring multiple files matching a pattern.
PSFTP:
PSCP: