CURL check for existing file

Is there a quick way to check if a file exists on a server using CURLMBS?

I use the following code with CURLMBS to check if an image file exists on my server. Hope it helps you, Christopher.

[code] // Check if image file exists on server
dim e as integer
dim d as new DownloadCURL

imgURL = ReplaceAll(imgURL, " ", “%20”) // NOTE: Spaces must be replaced with “%20” when using filenames having a URL

d.CollectOutputData = true
d.SetOptionHTTPHeader array(“Cache-Control: no-cache”)
d.OptionVerbose = true
d.CollectDebugData = true


dim de as string = d.DebugData

//ResultText2.text = “Result: “+str(e)+” and we got this file size: “+str(d.FileSize)+” Bytes”

if d.FileSize > 0 then // file exists
return true
else // file does not exist
return false
end if

Thx… will give it a swirl.

HTTP? FTP? SFTP? other protocol?

for HTTP, you could make a query with OptionHeader = true and see if you get error or not.
GetInfoResponsecode should be 200 and not 404.

for FTP, you could do directory listing and see if your file is there.

Found a way that works with FTP and SFTP when using MBS plugins (the above solution Don gave did only work for FTP and not SFTP).

  dim d as new DownloadCURL
  dim e as integer
  d.SetOptionHTTPHeader array("Cache-Control: no-cache")
  d.OptionURL=""+Files.Name     // Files is the FolderItem you need to check if it exists
  d.OptionUsername = "UserName"
  d.OptionPassword = "Password"
  select case e
  case 0
   msgbox "File found."
  case d.kError_COULDNT_CONNECT
    msgbox "Couldn't connect."
  case 9
    msgbox "Access Denied"
  case d.kError_LOGIN_DENIED
    msgbox "Login Denied"
    msgbox "File not found."