mwilliamson / spur.py

Run commands and manipulate files locally or over SSH using the same interface
BSD 2-Clause "Simplified" License
267 stars 37 forks source link

Pulling remote data locally #19

Closed atomicfireball closed 9 years ago

atomicfireball commented 9 years ago

I'm having issues pulling remote data to the local computer. Do you have any samples for this? I tried to open the remote file, (which seems like it worked) but I'm not sure how to save it locally.

atomicfireball commented 9 years ago

looks like it might be due to the file being of type: <type '_io.TextIOWrapper'>, when in fact it's not a text file. (think .png or .jpg)

atomicfireball commented 9 years ago

works correctly for standard text files.

mwilliamson commented 9 years ago

What code are you using? What exactly is the issue that you're having?

Files are opened in text mode by default, so opening them in binary mode (if you're not doing so already) might help:

with ssh_shell.open("/path/to/remote", "rb") as remote_file:
    with open("/path/to/local", "wb") as local_file:
        shutil.copyfileobj(remote_file, local_file)
atomicfireball commented 9 years ago

ah, I see. Perfect. Thanks.