James Hibbard
James Hibbard

Reputation: 17775

Is uploading a file using Ruby's Net::FTP class a synchronous operation?

I am using Ruby's Net::FTP class to upload a file to a remote server.

Net::FTP.open(SERVER, USER, PASS) do |ftp|
  do_foo
  ftp.puttextfile(bigfile.txt, bigfile.txt)
  do_bar
end

Will Ruby wait for puttextfile to finish uploading the file before executing the do_bar method?

If not, how can i have this happen?

Upvotes: 1

Views: 209

Answers (2)

hek2mgl
hek2mgl

Reputation: 158160

Yes the FTP upload is implemented as a synchronous operation meaning the next statement will be executed only after the upload has finished (or failed)

However, ftp.puttextfile allows to pass a callback which will get executed on every transmitted line. Docs

Upvotes: 2

Agis
Agis

Reputation: 33646

Yes, it is a synchronous operation.

However you can use execute the Net::FTP.open in a different thread if you want it to happen in parallel.

Upvotes: 1

Related Questions