I need to access a .csv file that is newly uploaded to an sftp every night. I would like to be able to access the data within the .csv file and display it in an html table on a webpage.
Previously the .csv sat on our server at a public url. I used php within a wordpress page template to open file and parse into an array which allowed me to output the data onto our webpage:
<?php
$filename = 'https://myoldfileurl.csv';
$my_array = [];
if (($h = fopen("{$filename}", "r")) !== FALSE)
{
while (($data = fgetcsv($h, 1000, ",")) !== FALSE)
{
$my_array[] = $data;
}
fclose($h);
}
?>
But now I need to get the .csv file from sftp instead of the public url as shown above. I am trying to accomplish the same thing. Access the file, open it and spit out its contents into an array that I can pull specific data points from. As mentioned, this is a wordpress site that I have developed locally. I added the SSH SFTP Updater Support plugin. Here is the code I have but I am not sure if this is the right way to go about it:
<?php
$connection = ssh2_connect('sftp.mysite.com', 22);
ssh2_auth_password($connection, 'username', 'password');
$sftp = ssh2_sftp($connection);
$stream = fopen('ssh2.sftp://' . intval($sftp) . '/Download/mydatafile.csv', 'r');
?>
When running the code I get the following error: Fatal error: Uncaught Error: Call to undefined function ssh2_connect().....
Any help is appreciated. Thank you!