How to check if file exists on FTP server using mkr 1400 GSM board...

Hi,
I am using the MKR 1400 GSM board to do FTP transfers from an FTP server using the following library found at (GitHub - tryhus/MKRGSM at feature/ftp). This library contains an FTP extension to the main MKRGSM library. This library works well and have been using it successfully for a while now however i would like to be able to check the existence of a file in a particular directory on the FTP server and i cant seem to see a way to do this using the given library methods. The idea is that if the file exists download it, if not bypass the download process.

I have tried the following:

 response("Connect to FTP server",
    ftp.connect(SERVER, USERNAME, PASSWORD, PORT));

  response("Change to current remote directory",
    ftp.cd(ftpPath));

  if (ftp.ls(remoteFile, "setup.ini")) {
    Serial.println(F("setup file found"));
  }
  else {
    Serial.println(F("No Config File on Server"));
    goto bypassWrite;
  }

However this does not work because i think it only returns FALSE if there are no files in the directory so does not work for detecting individual files.

Does anybody have any ideas on this or is there a better way of dong it.

Any help is much appreciated.

Cheers.

As you know the name of the file and its location on the FTP server can you not just try downloading the file? You will either get a 'file downloaded okay' or ' download error'.

Looking at the ls function...

/** Get informations of remote directory/file
@param file class that contains the information of all the files found
@param name name of file or directory where to search information
@param file name of file or directory where to search information
@param show if true, display information of files
@param timeout maximum time allow to execute the function
@return true if no error
*/
bool ls(GSMFTPElem& file, const String name, bool show = false, uint32_t timeout = 10000);

and it seems to indicate you can get info by setting show to true. What do you get when this happens?

Hi Riva,
And thanks for the reply.

Yes i previously tried this:

GSMFTPElem remoteFile;

response("check if file exists",
    ftp.ls(remoteFile, "setup.ini", true, 30000));

and also:

GSMFTPElem remoteFile;

if (ftp.ls(remoteFile, "setup.ini", true, 30000)) {
  Serial.println(F("setup file found"));
}
else {
  Serial.println(F("No Config File on Server"));
  goto bypassWrite;
}

And both times the method returns true wether the setup.ini file exists or not and does not display any files. However i may have used the method incorrectly?

Yes i could just try to download and if it fails then file is not present and do as previous but i just thought it would short cut the process slightly and be more efficient maybe by using a method that simply checks for existence of the file. But if that is not possible then that is what i will probably do.

Again, thanks for the reply. Any help is much appreciated.

Cheers.