Many times, when working with files and remote servers, it would be helpful if we could use code to manipulate directories and files to make processes more efficient.

In many organizations, Microsoft Excel files store data for different processes, and from time to time, we need to update the data stored in these files.

Having to update these files manually can be a nightmare. Adding to that, if you are working with remote servers, there will most likely need to be some copying back and forth to your local computer.

With Python, we can write a program that does these manipulations for us, and save a lot of headache.

Using Paramiko and Pandas, we can easily read xlsx files from a remote server.

How to Read an XLSX File from a Remote Server Using Pandas, Paramiko and FTP

Below is the code that I use to read xlsx files from a remote server using Pandas and Paramiko.

First, we connect to the server. Then we just need to open the Excel file and read from it using the .read_excel() pandas function.

import io
import paramiko
import pandas as pd

#connect to remote server

host = "yourhost"
username = "yourusername"
password = "yourpassword"

con = paramiko.SSHClient()
con.connect(host, username, password)
ftp = con.open_sftp()

#read in existing xlsx file contents to dataframe

existing_xlsx ="yourfilepath/existingfilename.xlsx")
df = pd.read_excel(existing_xlsx)

Hopefully, this post has helped you with automating a process using Python and manipulating Microsoft Excel files on your remote server.

Categorized in:


Last Update: February 26, 2024