Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't write CSV directly onto sftp.file.open #123

Open
dan-corneanu opened this issue Mar 30, 2021 · 1 comment
Open

can't write CSV directly onto sftp.file.open #123

dan-corneanu opened this issue Mar 30, 2021 · 1 comment

Comments

@dan-corneanu
Copy link

dan-corneanu commented Mar 30, 2021

io = sftp.file.open claims to produce an IO-like object. However, trying to use it as output for CSV gives an error.
Here is an example

require 'net/sftp'
require 'csv'

Net::SFTP.start(
      'localhost',
      'foo',
      password: 'pass',
    ) do |sftp|
      ftp_upload_path = 'upload/test_file.csv'
      sftp.file.open(ftp_upload_path, "w+") do |file|
        csv = CSV.new(file)
        csv << ["row", "of", "CSV", "data"]
      end
    end

This generate the following error

NoMethodError: undefined method `<<' for #<Net::SFTP::Operations::File:0x007f830419c718>
    from /Users/cdan/.rbenv/versions/2.3.0/lib/ruby/2.3.0/csv.rb:1692:in `<<'

The easy fix would be to probably implement Net::SFTP::Operations::File#<< in terms of Net::SFTP::Operations::File#write

This is similar.related to #65 .

@dan-corneanu dan-corneanu changed the title can generate CSV directly onto sftp.file.open can't generate CSV directly onto sftp.file.open Mar 30, 2021
@dan-corneanu dan-corneanu changed the title can't generate CSV directly onto sftp.file.open can't write CSV directly onto sftp.file.open Mar 30, 2021
@dan-corneanu
Copy link
Author

I've aliased << to write in Net::SFTP::Operations::File
See PR #124

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant