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

Copy local file to remote #142

Open
HarlemSquirrel opened this issue Oct 4, 2018 · 0 comments
Open

Copy local file to remote #142

HarlemSquirrel opened this issue Oct 4, 2018 · 0 comments

Comments

@HarlemSquirrel
Copy link

HarlemSquirrel commented Oct 4, 2018

I see in the write_file example we can write some data to a file.

file = tree.open_file(filename: file, write: true, disposition: RubySMB::Dispositions::FILE_OVERWRITE_IF)

result = file.write(data: data)
puts result.to_s
file.close

If I'm copying from an existing file I could do something like this

file = tree.open_file(filename: file, write: true, disposition: RubySMB::Dispositions::FILE_OVERWRITE_IF)

data = File.read(source_file)
result = file.write(data: data)
puts result.to_s
file.close

Is there perhaps a better way to simply copy an existing file (and overwrite on the destination) without having to read the source file into memory? I'm looking to copy over a file with tens of thousands of lines.

Maybe something like this?

file = tree.open_file(filename: file, write: true, disposition: RubySMB::Dispositions::FILE_OVERWRITE_IF)

line_num = 0
data = File.foreach(source_file) do |line|
  if line_num.zero?
    file.write data: line
  else
    file.append data: line
  end
  line_num += 1
end

puts "Wrote #{line_num} lines"
file.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants