I have a problem using “scp” from a ruby scrip. It copies my sql file to
the destination but it cuts the file the middle of line 290.
When i run scp manually i the copied file is normal.
What I’m using when scping is: scp -r dirToCopy destination ( -r for
recursive copy folder)
but, I believe that when dirToCopy or destination is remote, you should
write:
USER@IP:/FOLDER/FILE
in your lines I can’t see the @ sign
Could it be like: scp -r #{sql_folder} #{remotelogin}:#{remotesqlfolder}/#{document_id} scp -r #{sql_folder} #{remoteUSER}@#{remotesIP}:/#{document_id}
I have a problem using “scp” from a ruby scrip. It copies my sql file to
the destination but it cuts the file the middle of line 290.
When i run scp manually i the copied file is normal.
I want to emphasize this is just an off-the-wall guess. The backticked code is being forked, the parent process terminates prematurely, and
the
forked process is killed, also prematurely.
Have you tried “system” instead of back-ticks? “system” returns a
process
completion code, therefore it must wait until the process completes.
Could it be like: scp -r #{sql_folder} #{remotelogin}:#{remotesqlfolder}/#{document_id} scp -r #{sql_folder} #{remoteUSER}@#{remotesIP}:/#{document_id}
scp file #{remotemachine}:
is fine, it copies file to remotemachine to the home of the user with
the same name (or as preconfigured in .ssh/config - you can create
shortcuts for remotemachine and configure what the remote username
should be). You can add /remotefolder/remotefile after the colon to
change the remote location.
(The OP seems to know the proper syntax, as he is able to do it by hand.)
(I have no clue what the cause is, these are just hint what to try)
try another file (to see whether it is dependent on some pattern in
the file, or whether it transfers the same size all the time)
try removing few line around that line
try using system instead of ``
look at the logs on the remote side
Try the -v switch to scp. Perhaps it will break even more but perhaps
it would do the same and show useful information.
i spawn scp all the time from ruby, with gigantic files of tens of gigs
and
have never seen this. i think this maybe either an os issue or your
disk is
failing (though didn’t you mention it worked by hand?).
one other possiblity is some pipe filling issue. by using backticks you
are
relying on ruby to read stdout as fast as scp produces it. i can’t
imagine
why there would be an issue there, but i’d try your command using
something
like
I also rerun the script without deleting the sql file so it appended to
the file like it should. When i looked at the destination file i noticed
the file stopped at the same spot. But when i look up further to the top
of the destinatio file i noticed it had the a complete content of the
sql file followed by an incomplete content of the sql file. Ofcourse the
source has content of two complete sql files appended in one.
I also rerun the script without deleting the sql file so it appended to
the file like it should. When i looked at the destination file i noticed
the file stopped at the same spot. But when i look up further to the top
of the destinatio file i noticed it had the a complete content of the
sql file followed by an incomplete content of the sql file. Ofcourse the
source has content of two complete sql files appended in one.
I DON’T THINK IT’S scp ISSUE.
i get the same problem when i do this
On Thursday 07 September 2006 22:29, Joel VanderWerf wrote:
Pau Garcia i Quiles wrote:
Why won’t you use Net::SFTP instead of calling the external scp?
I can guess one reason. Net::SFTP doesn’t work with key-based
authentication, only passwords, and there is no password given in OP’s
code…
I hope that I am wrong and that this has changed recently.
On Thursday 07 September 2006 22:29, Joel VanderWerf wrote:
Pau Garcia i Quiles wrote:
Why won’t you use Net::SFTP instead of calling the external scp?
I can guess one reason. Net::SFTP doesn’t work with key-based
authentication, only passwords, and there is no password given in OP’s
code…
I hope that I am wrong and that this has changed recently.
Actually, it works with key-based authentication:
---- code -------------
require ‘rubygems’
require_gem ‘net-ssh’
require_gem ‘net-sftp’
Net::SSH.start( ‘host’,‘user’,‘password’) do |session|
session.sftp.connect do |sftp|
sftp.put_file("#{log}", “#{remotesqlfolder}/#{date_folder}.log”)
end
end
---- end of code ------
— error -------------
Even though it gave me bunch of warnings it copied the file. BUT i still
have the same problem and that is it chops from the bottom of the
destination file (N) bytes.
i have tried scp -r #{sql_folder} #{remotelogin}:#{remotesqlfolder}/
system(“scp -r #{sql_folder} #{remotelogin}:#{remotesqlfolder}/”)
system “scp -r #{sql_folder} #{remotelogin}:#{remotesqlfolder}”
and the aboth
All have the same problem @ the same spot of the file.
On Thursday 07 September 2006 22:29, Joel VanderWerf wrote:
Pau Garcia i Quiles wrote:
Why won’t you use Net::SFTP instead of calling the external scp?
I can guess one reason. Net::SFTP doesn’t work with key-based
authentication, only passwords, and there is no password given in OP’s
code…
I hope that I am wrong and that this has changed recently.
Actually, it works with key-based authentication:
require ‘net/ssh’
require ‘net/sftp’
Net::SSH.start( ‘192.168.1.37’,
:username=>‘pgquiles’
) do |session|
session.sftp.connect do |sftp|
sftp.put_file("backup.tar.bz2",
“/media/hda3/backup.tar.bz2”)
end
end
I get this error, not sure why?
---- code -------------
require ‘rubygems’
require_gem ‘net-ssh’
require_gem ‘net-sftp’
Net::SSH.start( ‘host’,‘user’,‘password’) do |session|
session.sftp.connect do |sftp|
sftp.put_file("#{log}", “#{remotesqlfolder}/#{date_folder}.log”)
end
end
---- end of code ------
— error -------------
/usr/lib/ruby/gems/1.8/gems/net-ssh-1.0.10/lib/net/ssh/userauth/services.rb:129:
warning: *' interpreted as argument prefix /usr/lib/ruby/gems/1.8/gems/net-ssh-1.0.10/lib/net/ssh/connection/driver.rb:74: warning:&’ interpreted as argument prefix
/usr/lib/ruby/gems/1.8/gems/net-ssh-1.0.10/lib/net/ssh/service/process/open.rb:130:
warning: &' interpreted as argument prefix /usr/lib/ruby/gems/1.8/gems/net-ssh-1.0.10/lib/net/ssh/service/process/open.rb:131: warning:&’ interpreted as argument prefix
/usr/lib/ruby/gems/1.8/gems/net-ssh-1.0.10/lib/net/ssh/service/process/open.rb:139:
warning: &' interpreted as argument prefix /usr/lib/ruby/gems/1.8/gems/net-ssh-1.0.10/lib/net/ssh/service/process/open.rb:140: warning:&’ interpreted as argument prefix
/usr/lib/ruby/gems/1.8/gems/net-ssh-1.0.10/lib/net/ssh/service/process/open.rb:141:
warning: &' interpreted as argument prefix /usr/lib/ruby/gems/1.8/gems/net-ssh-1.0.10/lib/net/ssh/service/process/open.rb:142: warning:&’ interpreted as argument prefix
/usr/lib/ruby/gems/1.8/gems/net-ssh-1.0.10/lib/net/ssh/service/process/popen3.rb:143:
warning: &' interpreted as argument prefix /usr/lib/ruby/gems/1.8/gems/net-ssh-1.0.10/lib/net/ssh/service/process/popen3.rb:162: warning:&’ interpreted as argument prefix
/usr/lib/ruby/gems/1.8/gems/net-sftp-1.1.0/lib/net/sftp/protocol/driver.rb:105:
warning: &' interpreted as argument prefix /usr/lib/ruby/gems/1.8/gems/net-sftp-1.1.0/lib/net/sftp/protocol/driver.rb:106: warning:&’ interpreted as argument prefix
/usr/lib/ruby/gems/1.8/gems/net-ssh-1.0.10/lib/net/ssh/connection/driver.rb:378:
warning: instance variable @processing_data_requests not initialized
/usr/lib/ruby/gems/1.8/gems/net-ssh-1.0.10/lib/net/ssh/connection/channel.rb:495:
warning: instance variable @on_window_adjust not initialized
/usr/lib/ruby/gems/1.8/gems/net-sftp-1.1.0/lib/net/sftp/operations/abstract.rb:64:
warning: `*’ interpreted as argument prefix
— end of error ------
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.