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.OptionNoBody=true
d.OptionURL=imgURL
d.CollectOutputData = true
d.SetOptionHTTPHeader array(“Cache-Control: no-cache”)
d.OptionVerbose = true
d.CollectDebugData = true

e=d.Perform

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
//MsgBox(imgURL)
d.ClearData
return true
else // file does not exist
d.ClearData
return false
end if
[/code]

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).

  [code]
  dim d as new DownloadCURL
  dim e as integer
  d.OptionNoBody=true
  d.SetOptionHTTPHeader array("Cache-Control: no-cache")
  d.OptionURL="ftp://ftp.Server.com/"+Files.Name     // Files is the FolderItem you need to check if it exists
  d.OptionUsername = "UserName"
  d.OptionPassword = "Password"
  e=d.Perform
  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"
  case d.kError_REMOTE_FILE_NOT_FOUND
    msgbox "File not found."
   end[/code]