From: Pau Garcia i Quiles Date: 2006-11-09T03:43:59+09:00 Subject: Re: Net::SSH Data Stream Problem --nextPart2646694.82fQx2m1pP Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Wednesday 08 November 2006 18:28, Andrew Stewart wrote: What about this: http://www.elpauer.org/index.php?p=3D213 require 'net/ssh' require 'net/sftp' class SSHAgent def initialize @agent_env =3D Hash.new agenthandle =3D IO.popen("/usr/bin/ssh-agent -s", "r") agenthandle.each_line do |line| if line.index("echo") =3D=3D nil line =3D line.slice(0..(line.index(';')-1)) key, value =3D line.chomp.split(/=3D/) puts "Key =3D #{key}, Value =3D #{value}" @agent_env[key] =3D value end end end def [](key) return @agent_env[key] end end agent =3D SSHAgent.new ENV["SSH_AUTH_SOCK"] =3D agent["SSH_AUTH_SOCK"] ENV["SSH_AGENT_PID"] =3D agent["SSH_AGENT_PID"] system("/usr/bin/ssh-add") Net::SSH.start( '192.168.1.12', :username=3D>'pgquiles', :compression_level=3D>0, :compression=3D>'none' ) do |session| session.sftp.connect do |sftp| sftp.put_file("bigvideo.avi", "bigvideo.avi") end end That code is using public-key, password-less cryptography, but with slight= =20 modifications it will work with public-key+password or only password. There= =20 is some more info about Net::SFTP in the blog post. > Hello, >=20 > I am trying to copy a file from my local machine to a remote machine =20 > using Net::SSH. The copy fails part way leaving the file partly =20 > written on the remote machine. The size of the remote file portion =20 > is always 131072 bytes (128 kB). My local file is ~1.2MB. This =20 > leads me to suspect that the data are being fed in chunks and =20 > something is going wrong after the first chunk -- though that's a guess. >=20 > Here's the output: >=20 > Copying /path/to/my/file.zip to /path/to/remote/directory/=20 > file.zip...done. > /usr/local/lib/ruby/gems/1.8/gems/net-ssh-1.0.9/lib/net/ssh/transport/=20 > session.rb:256:in `wait_for_message': disconnected: Received data for =20 > nonexistent channel 0. (2) (Net::SSH::Transport::Disconnect) > from /usr/local/lib/ruby/gems/1.8/gems/net-ssh-1.0.9/lib/net/=20 > ssh/transport/session.rb:240:in `wait_for_message' > from /usr/local/lib/ruby/gems/1.8/gems/net-ssh-1.0.9/lib/net/=20 > ssh/connection/driver.rb:148:in `process' > from /usr/local/lib/ruby/gems/1.8/gems/net-ssh-1.0.9/lib/net/=20 > ssh/connection/driver.rb:138:in `loop' > from /usr/local/lib/ruby/gems/1.8/gems/net-ssh-1.0.9/lib/net/=20 > ssh/service/process/popen3.rb:66:in `popen3' > [snipped rest of trace] >=20 > Interestingly the 'puts "...done."' line is executed before the error =20 > is thrown. Since session.process.popen3 is synchronous, does that =20 > not imply that the copy has finished? >=20 > And here's the code (based on Ruby Cookbook recipe 14.11): >=20 > require 'rubygems' > require 'net/ssh' >=20 > host =3D 'xyz.com' > user =3D 'me' > upload_dir =3D '/path/to/remote/directory/' > my_file =3D '/path/to/my/file.zip' >=20 > def copy_file(session, source_path, destination_path=3Dnil) > destination_path ||=3D source_path > cmd =3D %{cat > "#{destination_path.gsub('"', '\"')}"} > session.process.popen3 cmd do |stdin, stdout, stderr| > print "Copying #{source_path} to #{destination_path}..." > open(source_path) { |f| stdin.write f.read } > puts "done." > end > end >=20 > Net::SSH.start(host, :username =3D> user) do |session| > copy_file session, my_file, my_file.sub(/^.*\//, "#{upload_dir}") > end >=20 > I would greatly appreciate any help. >=20 > Thanks and regards, > Andy Stewart >=20 >=20 >=20 >=20 =2D-=20 Pau Garcia i Quiles http://www.elpauer.org (Due to the amount of work, I usually need 10 days to answer) --nextPart2646694.82fQx2m1pP Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQBFUiVk/DzYv9iGJzsRAoU2AJ9HKVMGPCKxsX9t1PLpuSsiBcq/OgCg+EXI qlkwBlhrEApFtHm7yfGf7bM= =ezSK -----END PGP SIGNATURE----- --nextPart2646694.82fQx2m1pP--