Greeting all,
I am stumped and I am hoping someone can help me out. I have been
running into an error when trying to download a file via SFTP. The
script I am using had been working until last week. I am still
searching for anything that might have been updated on my system, but
have had no luck.
This is the error:
$ ./get-sftpfile.rb -srcfilepath /remotedir/file.txt -dstfilepath
/localdir/file.txt
Connecting to remote SFTP server username at ftp.test.com
SSH Session open, starting SFTP.
SFTP Session open, connecting.
Logged into SFTP server, downloading file: /remotedir/file.txt
/usr/lib/ruby/1.8/net/sftp/operations/abstract.rb:78:in `do_status'':
Net::SFTP::Operations::StatusException (8, "The request is not
supported. ") (Net::SFTP::Operations::StatusException (8, "The request
is not supported. "))
from /usr/lib/ruby/1.8/net/sftp/session.rb:221:in `do_status''
from
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `to_proc''
from /usr/lib/ruby/1.8/net/sftp/protocol/01/impl.rb:92:in
`call''
from /usr/lib/ruby/1.8/net/sftp/protocol/01/impl.rb:92:in
`call_on_status''
from /usr/lib/ruby/1.8/net/sftp/protocol/03/impl.rb:37:in
`do_status''
from /usr/lib/ruby/1.8/net/sftp/protocol/01/impl.rb:189:in
`dispatch''
from /usr/lib/ruby/1.8/net/sftp/protocol/driver.rb:189:in
`do_data''
from
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `to_proc''
... 31 levels...
from /usr/lib/ruby/1.8/net/ssh.rb:47:in `new''
from /usr/lib/ruby/1.8/net/ssh.rb:47:in `start''
from ./get-sftpfile.rb:107:in `download_from_sftpserver''
from ./get-sftpfile.rb:131
The script is extremely simple. I''ve included it below.
get-sftpfile.rb:
#!/usr/bin/ruby
#=============================================================================
# Required modules
#-----------------------------------------------------------------------
--------
require ''rubygems''
require ''active_support''
require ''zip/zip''
require ''net/ssh''
require ''net/sftp''
require ''fileutils''
require ''ftools''
require ''find''
require ''optiflag''
module FTPtransferOptions extend OptiFlagSet
flag "srcfilepath" do
description "Full path to source file on SFTP server"
end
flag "dstfilepath" do
description "Full path to local destination for downloaded
file"
end
and_process!
end
#=============================================================================
# Program variables
#-----------------------------------------------------------------------
--------
src_filepath = ARGV.flags.srcfilepath
src_file = File.basename(src_filepath)
dst_filepath = ARGV.flags.dstfilepath
dst_dir = File.basename(dst_filepath)
repo_dir = "/home/file_repository/"
repo_filepath = repo_dir + src_file
sftp_server = "ftp.test.com" #Not a real server or credentials
sftp_user = "user"
sftp_pass = "password"
#=============================================================================
# Functions
#-----------------------------------------------------------------------
--------
def download_from_sftpserver(remote_filepath, sftpaddr, sftpuser,
sftppass, local_filepath)
puts "Connecting to remote SFTP server " + sftpuser +
"@" +
sftpaddr.to_s
Net::SSH.start(sftpaddr, sftpuser, sftppass) do |ssh_session|
puts "SSH Session open, starting SFTP."
Net::SFTP::Session.new(ssh_session) do |sftp_session|
puts "SFTP Session open, connecting."
sftp_session.connect
puts "Logged into SFTP server, downloading file:
"
+ remote_filepath
sftp_session.get_file(remote_filepath,
local_filepath)
puts "Download finished, logging out."
end
end
end
#=============================================================================
# Main Program
#-----------------------------------------------------------------------
--------
download_from_sftpserver(src_filepath, sftp_server, sftp_user,
sftp_pass, repo_filepath)
if File.exist?(repo_filepath)
FileUtils.cp(repo_filepath, dst_filepath)
if File.exist?(dst_filepath)
puts "File delivery successful: " + dst_filepath
puts "Encrypting repository copy..."
repo_encrypt_file(repo_filepath)
puts "Removing unencrypted file."
File.delete(repo_filepath)
puts "Job success - Exit 0"
exit 0
else
puts "Cannot deliver file to destination: " +
dst_filepath
puts "Job failure - Exit 2"
exit 2
end
else
puts "Cannot find repository file: " + repo_filepath
puts "Job failure - Exit 1"
exit 1
end
#=============================================================================
# The END
#=============================================================================
Does anyone have any ideas?
Thanks in advance for any help anyone is able to offer!
Jeff
Jeffery Smith - Server Administrator - jeffsmith at dcu.org
Digital Federal Credit Union - www.dcu.org
508-263-6851 desk | 774-245-7940 cell | 866-383-9879 fax
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/net-ssh-users/attachments/20081020/99f4e3c6/attachment-0001.html>