Python method to connect to a remote FTP server and list files in a directory

  • 2020-04-02 14:46:43
  • OfStack

This example demonstrates how python connects to a remote FTP server and lists files in a directory. Share with you for your reference. The details are as follows:

This python code to use the pysftp module, using the SFTP protocol, data encryption transfer


import pysftp
srv = pysftp.Connection(host="your_FTP_server", 
username="your_username",password="your_password")
# Get the directory and file listing
data = srv.listdir()
# Closes the connection
srv.close()
# Prints out the directories and files, line by line
for i in data:
  print i

I hope this article has helped you with your Python programming.


Related articles: