Writing to files on remote machine

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

Thank you.

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

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. Just be warned that sshfs can be horribly slow, so it won’t be appropriate in every use case.

2 Likes

In case you’re using Juno and want to edit and run files on a remote machine, take a look at this.

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

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

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

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

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

scp does the trick just fine. Thanks.

Just to give tcp - Who is better between netcat and scp in terms of authentication, confidentiality and performance? how - Stack Overflow

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