Skip to content

Instantly share code, notes, and snippets.

@divinediscipline
Last active February 10, 2020 18:10
Show Gist options
  • Save divinediscipline/4b9e62342b956e406c57fa1e34d8252f to your computer and use it in GitHub Desktop.
Save divinediscipline/4b9e62342b956e406c57fa1e34d8252f to your computer and use it in GitHub Desktop.
sftp error
# This is in a different file
require 'net/ssh'
require 'net/sftp'
class Sequoia::Export
def self.send_missing_assignments_to_sequoia(file_path)
Net::SFTP.start('sftp.bsiwighft.com', 'hirekkllarhjgjtsftp', :password => 'ZjcH!gkbg09bKFvH') do |sftp|
# upload a file or directory to the remote host
debugger
sftp.upload!(file_path, "/incoming")
end
end
end
# This is also in another different file
file_path = Rails.root.join('tmp', "hireart_sequoia_sftp_export_#{Time.now}.csv")
# assignments_to_be_sent_to_sequoia is an active record relation which is converted to a csv file using a to_csv method in my code
csv = assignments_to_be_sent_to_sequoia.to_csv
File.open(file_path, 'w') { |f| f.write csv }
Sequoia::Export.send_missing_assignments_to_sequoia(file_path)
@Harrisonkamau
Copy link

Add the following and let me know what logs you get:

def logger
  Rails.logger
end

def sftp
  @sftp ||= Net::SFTP.start(sftp_host, sftp_username, password: sftp_password)
end

Run the logger inside this dummy function to confirm that an SSH connection has been established:

def uploader(file_path)
  logger.info('Connected to SFTP')
  entries = sftp.dir.entries(file_path).select { |e| e.filename}
  logger.info("Found #{entries.size} files")
end

@Harrisonkamau
Copy link

Normally, the file_path should start with: /files/ followed by the folder where you are getting files from

@divinediscipline
Copy link
Author

Are you sure there was a connection established?

Yes. I'm very certain.
Was able to send a test readme at the root of my project this way:

sftp.upload!('README')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment