const ftpUrl = 'ftp://ftp.example.com'; // Replace with your FTP server URL const ftpFolder = '/pictures'; // Replace with the folder path of your pictures const ftpUsername = 'username'; // Replace with your FTP username const ftpPassword = 'password'; // Replace with your FTP password const websiteUrl = 'https://www.example.com'; // Replace with the URL of your website // Create an XMLHttpRequest object const xhr = new XMLHttpRequest(); // Set up a callback function to handle the response xhr.onreadystatechange = function() { if (this.readyState === 4 && this.status === 200) { // Parse the response text as XML const responseXml = new DOMParser().parseFromString(this.responseText, 'text/xml'); // Find the latest picture in the FTP folder const pictureElements = responseXml.getElementsByTagName('a'); let latestPicture = ''; let latestPictureTimestamp = 0; for (let i = 0; i < pictureElements.length; i++) { const picture = pictureElements[i].textContent; const pictureTimestamp = new Date(pictureElements[i].getAttribute('modified')).getTime(); if (picture.endsWith('.jpg') && pictureTimestamp > latestPictureTimestamp) { latestPicture = picture; latestPictureTimestamp = pictureTimestamp; } } // Display the latest picture on the website const pictureUrl = `${websiteUrl}${ftpFolder}/${latestPicture}`; const pictureElement = document.createElement('img'); pictureElement.src = pictureUrl; pictureElement.alt = 'Latest picture'; document.body.appendChild(pictureElement); } }; // Send an FTP GET request to retrieve the list of files in the FTP folder xhr.open('GET', `${ftpUrl}${ftpFolder}`, true, ftpUsername, ftpPassword); xhr.send();