# Writing to files on remote machine

**URL:** <https://discourse.julialang.org/t/writing-to-files-on-remote-machine/27356>\
**Category:** General Usage\
**Created:** [August 9, 2019, 5:11pm UTC](https://discourse.julialang.org/t/writing-to-files-on-remote-machine/27356 "2019-08-09T17:11:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [August 9, 2019, 5:11pm UTC](https://discourse.julialang.org/t/writing-to-files-on-remote-machine/27356/1 "2019-08-09T17:11:22Z")

</div>

How can I write a text file on a remote machine where I log on using ssh?

Thank you.

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [August 9, 2019, 5:29pm UTC](https://discourse.julialang.org/t/writing-to-files-on-remote-machine/27356/2 "2019-08-09T17:29:14Z")

</div>

You have to use `scp`, I don’t think there is a way around that (at least via `ssh`). If the question is how to use Julia to do this, you can write a file and then use Julia’s `run` to run an `scp` process. For example

```julia
writestuff(filename, data)
run(`scp $filename hostname:/path/to/newfile.txt`)
rm(filename)

```

`scp` should use your `.ssh/config`, so if you have that configured correctly it should really be this simple. Otherwise your `scp` command just gets slightly more complicated.

You can also look into [`sshfs`](http://man7.org/linux/man-pages/man1/sshfs.1.html). Just be warned that `sshfs` can be horribly slow, so it won’t be appropriate in every use case.

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [August 9, 2019, 5:44pm UTC](https://discourse.julialang.org/t/writing-to-files-on-remote-machine/27356/3 "2019-08-09T17:44:53Z")

</div>

In case you’re using Juno and want to edit and run files on a remote machine, take a look at [this](http://docs.junolab.org/latest/man/faq/#Connecting-to-a-Julia-session-on-a-remote-machine-1).

---

<div class="post-metadata">

**Author:** ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)\
**Post date:** [August 10, 2019, 6:07am UTC](https://discourse.julialang.org/t/writing-to-files-on-remote-machine/27356/4 "2019-08-10T06:07:30Z")

</div>

You can mount the directory on the remote machine using sshfs  
That means using ssh but having access l like a shared drive.

> **[How To Use SSHFS to Mount Remote File Systems Over SSH | DigitalOcean](https://www.digitalocean.com/community/tutorials/how-to-use-sshfs-to-mount-remote-file-systems-over-ssh)**
>
> Luckily there is a way to mount your VPS file system to your local computer so you can make changes on the fly and treat your droplet as local storage.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 10, 2019, 6:25am UTC](https://discourse.julialang.org/t/writing-to-files-on-remote-machine/27356/5 "2019-08-10T06:25:57Z")

</div>

I think you can also pipe directly to `ssh`, eg piping to a `Cmd` like

```julia
`ssh user@remote.host "cat > /remote/file"`

```

That said, `scp` may be more robust for large files, I didn’t test.

---

<div class="post-metadata">

**Author:** ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)\
**Post date:** [August 10, 2019, 10:58am UTC](https://discourse.julialang.org/t/writing-to-files-on-remote-machine/27356/6 "2019-08-10T10:58:32Z")

</div>

In the old days you would use netcat for that sort of pipe. Probably still do!

> **[netcat](https://en.wikipedia.org/wiki/Netcat)**
>
> netcat (often abbreviated to nc) is a computer networking utility for reading from and writing to network connections using TCP or UDP. The command is designed to be a dependable back-end that can be used directly or easily driven by other programs and scripts. At the same time, it is a feature-rich network debugging and investigation tool, since it can produce almost any kind of connection its user could need and has a number of built-in capabilities.
> It is able to perform port scanning, file t...

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [August 10, 2019, 11:23am UTC](https://discourse.julialang.org/t/writing-to-files-on-remote-machine/27356/7 "2019-08-10T11:23:29Z")

</div>

`scp` does the trick just fine. Thanks.

---

<div class="post-metadata">

**Author:** ![fieldofnodes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fieldofnodes/32/15858_2.png) [@fieldofnodes](https://discourse.julialang.org/u/fieldofnodes)\
**Post date:** [January 13, 2022, 9:45am UTC](https://discourse.julialang.org/t/writing-to-files-on-remote-machine/27356/8 "2022-01-13T09:45:40Z")

</div>

Just to give [tcp - Who is better between netcat and scp in terms of authentication, confidentiality and performance? how - Stack Overflow](https://stackoverflow.com/a/57650060/4938887)

This details the 50,000 level difference or netcat and scp.
