Found the solution
ssh_session = Net::SSH.start(...etc...)
sftp_conn = ssh_session.sftp.connect! # needed to block connect here
(!) or the upload seems to hang
sftp_conn.upload(src_file, tgt_file)
interrupted = false
trap('INT') { interrupted = true }
sftp_conn.loop() {
not interrupted and sftp_conn.pending_requests.any? # check for
pending requests
}
sftp_conn.close_channel()
ssh_session.loop(1) {
not interrupted and ssh_session.busy?
}
sftp_conn = ssh_session.sftp.connect!
One word of warning if sending lots of files (>300) fast then you may
run out of open file handles (Windows).
I avoid the error by doing this call each now and then when starting
another upload
if (sftp_conn.pending_requests.length>=100)
interrupted = false
trap('INT') { interrupted = true }
sftp_conn.loop() {
not interrupted and sftp_conn.pending_requests.any?
}
end
I guess I could have exited when the queue was smaller not empty also.
Hope this helps someone else.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---