Code Monkey home page Code Monkey logo

Comments (10)

nickheaphy avatar nickheaphy commented on August 15, 2024 1

That's a good idea.

I think I also have a strategy for figuring out my Reader.Length which in my limited testing seems to be working and the file transfer seems to be matching when comparing checksums. Next week I will try with more than just simulated data.

Thanks for all your help.

from rb-libcurl.

charonn0 avatar charonn0 commented on August 15, 2024

It sounds like you're using the demo window. What happens if you use the cURLClient class directly?

  Dim file As FolderItem = SpecialFolder.Desktop.Child("file.pdf")
  Dim upload As BinaryStream = BinaryStream.Open(file)
  Dim curl As New cURLClient
  curl.Username = "username"
  curl.Password = "password"
  
  If curl.Put("smb://192.168.1.10/delete-me/file.pdf", upload) Then
    MsgBox("Success")
  Else
    MsgBox("Error: " + libcURL.FormatError(curl.LastError))
  End If
  upload.Close()

My suspicion is that the problem lies in the demo window rather than in the project proper.

from rb-libcurl.

nickheaphy avatar nickheaphy commented on August 15, 2024

Funnily enough, I just sat down to write a minimal example like you posted as I wondered something similar.

With your above code I run into the same problem. I never get either of the Success or Error MsgBox popups. The main thread hangs. The debug messages shows the "Connected to 192.168.1.10 (192.168.1.10) port 445 (#0)" but then nothing.

If I break out into the debugger it is always in the cURLSession.Perform function. Stepping through it seems like the MultiHandle.PerformOnce function just keeps looping (but to be honest I don't understand exactly what is happening, your code is way above my head!)

Again, if I change to a WebDav URL, everything works as expected.

from rb-libcurl.

charonn0 avatar charonn0 commented on August 15, 2024

There is a known bug (curl/curl#7896) in curl where SMB uploads from stdin generate an empty file and then hang. It's not quite the same (we're not using stdin), but otherwise it seems to match. One of the comments suggests that specifying the upload size in advance might help:

Call curl.SetOption(libcURL.Opts.INFILESIZE, file.Length) ' use INFILESIZE_LARGE for files >2GB

It might also be enlightening to see the debug output from a successful command line upload. Add -v to the command line for verbose mode.

from rb-libcurl.

nickheaphy avatar nickheaphy commented on August 15, 2024

Spending a bit more time trying to understand what is happening... for some reason the code keeps entering EasyHandle.curlRead even though the UploadStream.Read(sz) returns 0 bytes because it is at the end of the file.

Not much info in the verbose output.

nick.h@Nicks-MBP Desktop % curl -v -T file.pdf -u user:password smb://192.168.1.10/delete-me/file.pdf
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 192.168.1.10:445...
* Connected to 192.168.1.10 (192.168.1.10) port 445 (#0)
100 25024    0     0  100 25024      0   374k --:--:-- --:--:-- --:--:--  444k
* Connection #0 to host 192.168.1.10 left intact

I will try adding the file size and see if that helps.

from rb-libcurl.

nickheaphy avatar nickheaphy commented on August 15, 2024

Genius!

Adding Call curl.SetOption(libcURL.Opts.INFILESIZE, file.Length) before curl.Put gives a successful upload!

from rb-libcurl.

nickheaphy avatar nickheaphy commented on August 15, 2024

Hmmmm, now I just need to work out how I implement that in my code with the custom Readable class that I have written that does not know the size of the data... nuts 🤣

from rb-libcurl.

charonn0 avatar charonn0 commented on August 15, 2024

According to the libcurl documentation:

This option (INFILESIZE) does not limit how much data libcurl will actually send, as that is controlled entirely by what the read callback returns, but telling one value and sending a different amount may lead to errors.

So maybe if you specify a ridiculously large size in advance? It might generate an error, but I wonder if the file will be uploaded anyway.

from rb-libcurl.

nickheaphy avatar nickheaphy commented on August 15, 2024

Thanks. I had the same thought but when I tried it was back to hanging, stuck in the same cURLSession.Perform loop.

I am working on my code with some known file lengths to make sure that setting the filesize works in conjunction with the custom Readable class, then I will have a think about the best way to deal with the unknown (maybe just telling the users they have to use WebDAV 😜)

from rb-libcurl.

charonn0 avatar charonn0 commented on August 15, 2024

Calling cURLClient.Abort() should break the loop and cause an error. This will require some juggling since the code that waits for the EOF has to run concurrently with the code that's performing the transfer. Which means either using asynchronous transfers to run both on the event loop/main thread, or using two separate threads.

curl.Put("smb://192.168.1.10/delete-me/file.pdf", upload) ' async Put()
Do Until upload.EOF
  App.DoEvents()   // do not do this in real code. Use a Timer to detect the EOF
Loop
curl.Abort()
upload.Close()

from rb-libcurl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.