Copying Text-Files from a Remote Server to the Clipboard
Method 1 : Using SSH
To connect to a remote SSH server and copy the contents of a file, you can use the following command. This command executes cat on the remote server and pipes the output into xclip
to copy it to the clipboard:
ssh -n USER@REMOTE "cat /home/riven/somefile" | xclip -selection clipboard
Note: You need to have the xclip package installed on your local machine.
IF you have the following error :
cat some/file.txt | xclip
Error: Can't open display: (null)
Do the following fix :
$ export DISPLAY=:0
$ echo 'some text' | xclip -selection clipboard
Method 2 : Using NetCat
This method does not require SSH access; instead, it utilizes the netcat-openbsd
package.
On the Remote Host:
To listen for incoming connections and send the contents of a file, run:
cat FILE | nc -lvnp 4000
On the Local Host:
You can receive the file using nc:
nc -v REMOTE 4000 | xclip -selection clipboard
Alternatively, you can use wget to save the file directly:
wget -O- REMOTE:PORT > FILE
Method 2 : Using HTTP Server
You can easily launch an HTTP server using various methods:
Using python3 :
To start a simple HTTP server, run:
python3 -m http.server 8080
Using PHP :
To launch an HTTP server with PHP, use:
php -S 127:0.0.1:8000
Or, to specify a document root:
php -S 127:0.0.1:8000 -t /var/lib/www
While you can also use more advanced servers like Nginx or Apache, they may be overly complex for our needs.