Python FTP Connection and CSV Download

Job ID: 38468978

Budget: €8 – €30 EUR

I'm seeking a Python expert to troubleshoot and enhance my code for connecting to an FTP server using the paramiko library.

Key tasks include:
- Correcting existing code for accessing the FTP server: 'sftp.datamine.cmegroup.com'
- Ensuring successful connection and file download
- Downloading specified CSV files from the server

Ideal candidates should have:
- Proficiency in Python and paramiko library
- Experience with FTP connections
- Ability to work with CSV files

The ultimate goal is to connect to the server and download CSV files via my Python script, similar to what I can achieve with Filezilla.

here is my code :
def download_sftp_folder1(remote_folder, local_folder):

host='sftp.datamine.cmegroup.com'
port=2222
username='api_bviguier'
password='mypassword'

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

try:
# Connect to the server
ssh.connect(host, port, username, password)
print("SSH connection successful")

# Open an SFTP session
sftp = ssh.open_sftp()
print("SFTP session opened successfully")

# Test listing files in the root directory
print("Listing files in the root directory:")
files = sftp.listdir('/')
print(files)

sftp.close()
print("SFTP session closed")

except paramiko.AuthenticationException:
print("Authentication failed, please verify your credentials")
except paramiko.SSHException as e:
print(f"SSH error: {e}")
except paramiko.SFTPError as e:
print(f"SFTP error: {e}")
except Exception as e:
print(f"General error: {e}")
finally:
ssh.close()
if __name__ == "__main__":
download_sftp_folder1('/2024/08/01', 'downloaded_files')
Related categories: Python Linux Ubuntu