--- !ruby/object:RI::ClassDescription 
attributes: 
- !ruby/object:RI::Attribute 
  comment: 
  - !ruby/struct:SM::Flow::P 
    body: The source of the upload (on the local server)
  name: local
  rw: R
- !ruby/object:RI::Attribute 
  comment: 
  - !ruby/struct:SM::Flow::P 
    body: The hash of options that were given when the object was instantiated
  name: options
  rw: R
- !ruby/object:RI::Attribute 
  comment: 
  - !ruby/struct:SM::Flow::P 
    body: The properties hash for this object
  name: properties
  rw: R
- !ruby/object:RI::Attribute 
  comment: 
  - !ruby/struct:SM::Flow::P 
    body: The destination of the upload (on the remote server)
  name: remote
  rw: R
- !ruby/object:RI::Attribute 
  comment: 
  - !ruby/struct:SM::Flow::P 
    body: The SFTP session object used by this upload instance
  name: sftp
  rw: R
class_methods: []

comment: 
- !ruby/struct:SM::Flow::P 
  body: A general purpose uploader module for Net::SFTP. It can upload IO objects, files, and even entire directory trees via SFTP, and provides a flexible progress reporting mechanism.
- !ruby/struct:SM::Flow::P 
  body: "To upload a single file to the remote server, simply specify both the local and remote paths:"
- !ruby/struct:SM::Flow::VERB 
  body: "  uploader = sftp.upload(&quot;/path/to/local.txt&quot;, &quot;/path/to/remote.txt&quot;)\n"
- !ruby/struct:SM::Flow::P 
  body: "By default, this operates asynchronously, so if you want to block until the upload finishes, you can use the 'bang' variant:"
- !ruby/struct:SM::Flow::VERB 
  body: "  sftp.upload!(&quot;/path/to/local.txt&quot;, &quot;/path/to/remote.txt&quot;)\n"
- !ruby/struct:SM::Flow::P 
  body: "Or, if you have multiple uploads that you want to run in parallel, you can employ the #wait method of the returned object:"
- !ruby/struct:SM::Flow::VERB 
  body: "  uploads = %w(file1 file2 file3).map { |f| sftp.upload(f, &quot;remote/#{f}&quot;) }\n  uploads.each { |u| u.wait }\n"
- !ruby/struct:SM::Flow::P 
  body: "To upload an entire directory tree, recursively, simply pass the directory path as the first parameter:"
- !ruby/struct:SM::Flow::VERB 
  body: "  sftp.upload!(&quot;/path/to/directory&quot;, &quot;/path/to/remote&quot;)\n"
- !ruby/struct:SM::Flow::P 
  body: This will upload &quot;/path/to/directory&quot;, it's contents, it's subdirectories, and their contents, recursively, to &quot;/path/to/remote&quot; on the remote server.
- !ruby/struct:SM::Flow::P 
  body: "If you want to send data to a file on the remote server, but the data is in memory, you can pass an IO object and upload it's contents:"
- !ruby/struct:SM::Flow::VERB 
  body: "  require 'stringio'\n  io = StringIO.new(data)\n  sftp.upload!(io, &quot;/path/to/remote&quot;)\n"
- !ruby/struct:SM::Flow::P 
  body: "The following options are supported:"
- !ruby/object:SM::Flow::LIST 
  contents: 
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:progress</tt> - either a block or an object to act as a progress callback. See the discussion of &quot;progress monitoring&quot; below.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:requests</tt> - the number of pending SFTP requests to allow at any given time. When uploading an entire directory tree recursively, this will default to 16, otherwise it will default to 2. Setting this higher might improve throughput. Reducing it will reduce throughput.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:read_size</tt> - the maximum number of bytes to read at a time from the source. Increasing this value might improve throughput. It defaults to 32,000 bytes.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:name</tt> - the filename to report to the progress monitor when an IO object is given as <tt>local</tt>. This defaults to &quot;&lt;memory&gt;&quot;.
  type: :BULLET
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Progress Monitoring
- !ruby/struct:SM::Flow::P 
  body: "Sometimes it is desirable to track the progress of an upload. There are two ways to do this: either using a callback block, or a special custom object."
- !ruby/struct:SM::Flow::P 
  body: "Using a block it's pretty straightforward:"
- !ruby/struct:SM::Flow::VERB 
  body: "  sftp.upload!(&quot;local&quot;, &quot;remote&quot;) do |event, uploader, *args|\n    case event\n    when :open then\n      # args[0] : file metadata\n      puts &quot;starting upload: #{args[0].local} -&gt; #{args[0].remote} (#{args[0].size} bytes}&quot;\n    when :put then\n      # args[0] : file metadata\n      # args[1] : byte offset in remote file\n      # args[2] : data being written (as string)\n      puts &quot;writing #{args[2].length} bytes to #{args[0].remote} starting at #{args[1]}&quot;\n    when :close then\n      # args[0] : file metadata\n      puts &quot;finished with #{args[0].remote}&quot;\n    when :mkdir then\n      # args[0] : remote path name\n      puts &quot;creating directory #{args[0]}&quot;\n    when :finish then\n      puts &quot;all done!&quot;\n  end\n"
- !ruby/struct:SM::Flow::P 
  body: "However, for more complex implementations (e.g., GUI interfaces and such) a block can become cumbersome. In those cases, you can create custom handler objects that respond to certain methods, and then pass your handler to the uploader:"
- !ruby/struct:SM::Flow::VERB 
  body: "  class CustomHandler\n    def on_open(uploader, file)\n      puts &quot;starting upload: #{file.local} -&gt; #{file.remote} (#{file.size} bytes)&quot;\n    end\n\n    def on_put(uploader, file, offset, data)\n      puts &quot;writing #{data.length} bytes to #{file.remote} starting at #{offset}&quot;\n    end\n\n    def on_close(uploader, file)\n      puts &quot;finished with #{file.remote}&quot;\n    end\n\n    def on_mkdir(uploader, path)\n      puts &quot;creating directory #{path}&quot;\n    end\n\n    def on_finish(uploader)\n      puts &quot;all done!&quot;\n    end\n  end\n\n  sftp.upload!(&quot;local&quot;, &quot;remote&quot;, :progress =&gt; CustomHandler.new)\n"
- !ruby/struct:SM::Flow::P 
  body: If you omit any of those methods, the progress updates for those missing events will be ignored. You can create a catchall method named &quot;call&quot; for those, instead.
constants: 
- !ruby/object:RI::Constant 
  comment: 
  - !ruby/struct:SM::Flow::P 
    body: A simple struct for recording metadata about the file currently being uploaded.
  name: LiveFile
  value: Struct.new(:local, :remote, :io, :size, :handle)
- !ruby/object:RI::Constant 
  comment: 
  - !ruby/struct:SM::Flow::P 
    body: "The default # of bytes to read from disk at a time."
  name: DEFAULT_READ_SIZE
  value: 32_000
- !ruby/object:RI::Constant 
  comment: 
  - !ruby/struct:SM::Flow::P 
    body: The number of readers to use when uploading a single file.
  name: SINGLE_FILE_READERS
  value: "2"
- !ruby/object:RI::Constant 
  comment: 
  - !ruby/struct:SM::Flow::P 
    body: The number of readers to use when uploading a directory.
  name: RECURSIVE_READERS
  value: "16"
full_name: Net::SFTP::Operations::Upload
includes: 
- !ruby/object:RI::IncludedModule 
  name: Net::SSH::Loggable
instance_methods: 
- !ruby/object:RI::MethodSummary 
  name: "[]"
- !ruby/object:RI::MethodSummary 
  name: "[]="
- !ruby/object:RI::MethodSummary 
  name: abort!
- !ruby/object:RI::MethodSummary 
  name: active?
- !ruby/object:RI::MethodSummary 
  name: recursive?
- !ruby/object:RI::MethodSummary 
  name: wait
name: Upload
superclass: Object
