Funnily enough, I've never actually tried uploading until now, so apologies for a lack of examples.
Anyhoo, here's one which I've tested on my server and it seemed to work :-)
I created a "helper" Type to look after the streaming, all in the name of good code re-use.
Not sure if we need to close the stream afterwards, or if it is closed when the variable is GC'd...
Here it is :
SuperStrict
Framework BaH.libcurl
Import BRL.StandardIO
Import BRL.FileSystem
Local curl:TCurlEasy = TCurlEasy.Create()
' Just here for keeping an eye on things
curl.setOptInt(CURLOPT_VERBOSE, 1)
curl.setDebugCallback(debugFunction)
' Create our upload-helper :-)
Local upload:UploadHelper = UploadHelper.Create("ftptest.bmx")
' ftp connect and initial directory
curl.setOptString(CURLOPT_URL, "<full FTP URL including filename to upload>")
curl.setOptString(CURLOPT_USERPWD, "user:password")
curl.setOptInt(CURLOPT_UPLOAD, True)
' set the upload size
curl.setOptLong(CURLOPT_INFILESIZE_LARGE, upload.size)
' set the callback
curl.setReadCallback(upload.Read, upload)
' do the UPLOAD !
Local res:Int = curl.perform()
If res Then
Print "***** " + CurlError(res) + " *****"
End If
curl.cleanup()
End ' Fini!
' for our debugging
Function debugFunction:Int(data:Object, msgType:Int, message:String)
' we only care about server info
If msgType = CURLINFO_HEADER_IN Then
Print message
End If
End Function
' This just processes a filestream for us.
' DoRead, does the hard work of feeding the callback buffer with data from the stream.
Type UploadHelper
Field name:String
Field size:Int
Field currentPos:Int
Field stream:TStream
Function Create:UploadHelper(file:String)
Local this:UploadHelper = New UploadHelper
this.name = file
this.size = FileSize(file)
Return this
End Function
Method DoRead:Int(buffer:Byte Ptr, size:Int)
If Not stream Then
stream = ReadStream(name)
currentPos = 0
End If
Local count:Int = Stream.Read( buffer, size )
currentPos :+ count
Return count
End Method
Function Read:Int(buffer:Byte Ptr, size:Int, data:Object)
Return UploadHelper(data).DoRead(buffer, size)
End Function
End Type