How to transfer files to the server with PSFTP command-line tool

FTP (File Transfer Protocol) is a network communication protocol used to transfer files between two computers (client-server mode). The following shows how to transfer files between your local computers and the linux server using secured FTP called PSFTP (a variant of FTP), which can be downloaded for free along with Putty software tool.

For example, to transfer html files from your computer to the directory /home/jdoe/public_html on the server, open the PSFTP tool first as below. Note "jdoe" is a sample username on the server.

Start -> All Programs -> PuTTY ->PSFTP. On the prompt, type "open jdoe@cs1.txwes.edu" to establish a connection to the server and then enter your private key. Below is a sample for the connection.

psftp> open jdoe@cs1.txwes.edu
Using username "jdoe".
Passphrase for key "eddsa-key-20231209":

Remote working directory is /home/jdoe
By default, you are directed to your home directory on the server. When transfering files between two computers, it is important to specify a source directory where files will be transfered from and a destination directory where files will be transfered to, that is, commands need to know where to transfer files from and to. To transfer files to the web directory "public_html," you need to set it as the destination directory by typing a command "cd public_html" and use command "lcd" to set a source directory on your local computer where the files will be transferred from. "l" in the command "lcd" means local (your local computer). The commands on this PSFTP console window can apply to either local or remote computers.

If you want to transfer a file named "index.html" from C:\Users\Jdoe\Documents on your local machine to the web directory "public_html" on the server. First, navigate to the source directory using "lcd" as below.

lcd C:\Users\Jdoe\Documents

Use command "put" to transfer files to the server.

psftp>put index.html

If you want to transfer multiple files with a single command, you can use

psftp>mput *.html
to transfer all the files with extension of html. * is a wild card meaning "don't care" the file names. If you want to download files to your local machine from the remote server, you can use
psftp>get index.html
"mget" is for getting multiple files.

In a netshell, the PSFTP command-line tool is very powerful and useful for file transfer between client and server machines. Once you specify a source directory and a destination directory, you can use a single command to transfer multiple files easily, especially for uploading or downloading an entire website with thousands of web files.