Ken E.
3 min readOct 19, 2023

Building an Intuitive SFTP Client with PySimpleGUI and Paramiko

File transfer is a fundamental operation in the world of networking. Whether it’s for backing up your data, updating a website, or sharing files, SFTP (Secure File Transfer Protocol) is a go-to choice. Today, I’ll introduce you to an SFTP client application I built using Python, leveraging the power of PySimpleGUI and paramiko.

Why Another SFTP Client?

While there are numerous SFTP client applications available, many come with a steep learning curve or are bogged down with features that aren’t always necessary. My aim was to build a lightweight, user-friendly SFTP client that gets the job done without the frills.

The Power of PySimpleGUI

Traditionally, building GUIs in Python involved using tkinter. While powerful, tkinter can be verbose. Enter PySimpleGUI. It provides a simplified way to create GUIs by abstracting away the complexities. With just a few lines of code, you can have a functional GUI up and running.

Secure File Transfers with Paramiko

Paramiko is a Python library that facilitates SSH2 protocol operations, including SFTP. With paramiko, handling file uploads, downloads, and directory listings becomes a breeze.

Features of Our SFTP Client

  • Fast Connections: Quickly connect to your SFTP server with just a few clicks.
  • Intuitive UI: A straightforward interface ensuring even beginners feel right at home.
  • Secure Transfers: Thanks to paramiko, your file transfers are secure and efficient.
  • A look at our SFTP Client in action.

How Can You Use It?

The application is open-source and available on GitHub.

import PySimpleGUI as sg
import paramiko

# sg.theme_previewer()
sg.theme('DarkTeal12')
class SFTPClient:

def __init__(self, host, username, password, port=22):
self.client = paramiko.SSHClient()
self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.client.connect(host, port, username, password)
self.sftp = self.client.open_sftp()

def list_files(self, path='.'):
return self.sftp.listdir(path)

def download(self, remote_path, local_path):
self.sftp.get(remote_path, local_path)

def upload(self, local_path, remote_path):
self.sftp.put(local_path, remote_path)

def close(self):
self.sftp.close()
self.client.close()

class SFTPDialog:

def __init__(self):
layout = [
[sg.Text("Host:"), sg.Input(key="host")],
[sg.Text("Username:"), sg.Input(key="username")],
[sg.Text("Password:"), sg.Input(key="password", password_char="*")],
[sg.Text("Port:"), sg.Input(key="port", default_text="22")],
[sg.Button("Connect")],
[sg.Listbox(values=[], size=(40, 10), key="filelist")],
[sg.Button("Download"), sg.Button("Upload")]
]

self.window = sg.Window("SFTP Client", layout)
self.client = None

def connect(self):
values = self.window.read()[1]
host = values["host"]
username = values["username"]
password = values["password"]
port = int(values["port"])

self.client = SFTPClient(host, username, password, port)
filelist = self.client.list_files()
self.window["filelist"].update(filelist)

def download(self):
# Implement the download logic, for simplicity, let's assume downloading to the current directory
selected_file = self.window["filelist"].get()[0]
self.client.download(selected_file, selected_file)

def upload(self):
# Implement the upload logic, for simplicity, assume uploading a file from the current directory
selected_file = self.window["filelist"].get()[0]
self.client.upload(selected_file, selected_file)

def run(self):
while True:
event, values = self.window.read()

if event == "Connect":
self.connect()

if event == "Download":
self.download()

if event == "Upload":
self.upload()

if event == sg.WINDOW_CLOSED:
break

if self.client:
self.client.close()

self.window.close()

def main():
dialog = SFTPDialog()
dialog.run()

if __name__ == "__main__":
main()Wrapping Up

Building this SFTP Client was a fulfilling experience. Not only did it teach me the nuances of file transfers, but it also introduced me to the wonders of PySimpleGUI. If you ever need a simple yet functional SFTP client or want to dive into the world of GUI development with Python, I highly recommend giving this project a shot.

Ken E.

🔍 Exploring the Intersection of GRC and Technology 🌐 | Passionate GRC Professional with a Tech Twist 🚀 | Embracing the Future of emerging technology.