Reputation: 1
I'm using the ruby library Net-SFTP to upload a folder of a files to a remote server using the upload! command, and finding that when I regain control, the folder has not finished uploading. It wouldn't be all that important except for the fact that I need to change the permissions of this folder and I can't accomplish them through the upload command due to a umask on the remote server. I do not have a root account on the remote server, so basically I need to wait for the folder to be there, then change its permissions. When I try to change the permissions, sometimes the folder is not there yet, but will show up eventually. I guess my question is two-fold.
1.) Why isn't the blocking call to upload! actually blocking until the folder has been created. 2.) Is there some way of forcing it to block with a lower level call, or do I have to wait a couple of seconds and then poll to see if the folder is there yet?
UPDATE: I suspect the real issue is because I'm trying to change permissions over a separate ssh connection, which may or may not be the same machine as I'm logging into a cluster. In other words, the folder has been created on one machine, but it hasn't been replicated across the others by the time I try to change permissions. Is there some way to close a question?
Upvotes: 0
Views: 1019
Reputation: 9369
You could try using the SFTP Session's underlying SSH session to run the command:
Net::SSH.start("localhost", "user", "password") do |ssh|
ssh.sftp.upload!("/local/file.tgz", "/remote/file.tgz")
ssh.exec! "cd /some/path && tar xf /remote/file.tgz && rm /remote/file.tgz"
end
http://net-ssh.github.io/net-sftp/classes/Net/SSH/Connection/Session.html
Or you could let SFTP change the permissions:
sftp.setstat("/path/to/remote.file", :permissions => 0644)
http://net-ssh.github.io/sftp/v1/faq.html#2202822
Upvotes: 1
Reputation: 34308
The v2 SFTP docs say specifically that upload!
blocks until the operation is complete:
http://net-ssh.rubyforge.org/sftp/v2/api/classes/Net/SFTP/Session.html#M000116
However if you're running a concurrent SFTP or SSH session, then you are on your own. You have to manually poll for the operation to be complete, or synchronize your sessions some other way.
To manually poll you can do it with something like a loop using sleep
to continuously check the remote end until the folder you are expecting appears.
Upvotes: 0