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

Answers

  • @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.

  • 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: