question

Upvotes
1 1 3 2

LSEG Machine Readable News Archive

Hello - We are trying to understand how to programmatically access the machine readable news archive via SFTP, in either Python or R. This is part of the Delivery Platform. We are hoping there are others with experience of using this within the community. Would anyone be able to share a code example? Thanks

#technologyrdpmachine-id
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
85k 289 53 77

@darren.rogers

Thank you for reaching out to us.

To use SFTP with Python or R, you need to use the package that can establish a secure connection to the SFTP server. You can find the SFTP Python packages by searching this "python sftp" keyword on Google.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
27.2k 65 17 14

Hello @darren.rogers

Like my colleague has suggested you above, you can use any Python SFTP libraries such as paramiko or pysftp and much more to connect to the MRN SFTP remote server.

I did a quick test with paramiko and it works fine.

Example Code (without any exceptions handling):

import paramiko

username = 'YOUR_MACHINE_ID'
password = 'YOUR_PASSWORD'
hostname = 'archive.news.refinitiv.com'

#Establish the SSH client
ssh = paramiko.SSHClient()
# Automatically add host keys (not secure for production)
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())  

# Connect to the server
ssh.connect(hostname=hostname, username=username, password=password)

# Establish the SFTP client
sftp = ssh.open_sftp()

# check the current directory
print(sftp.listdir())

# Get the file
sftp.chdir('/mpsych/MI4/CMPNY_REF/BASIC')
print(sftp.listdir())
# Get the first file name
fileName = sftp.listdir()[0]
# Download the file
sftp.get(remotepath = fileName, localpath=f'.\download\{fileName}')

# Close a connection
sftp.close()

Result:

result-mrn.png

You can find more detail about the paramiko library from the following websites:


result-mrn.png (63.3 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.