In some cases when you cannot use “ftp/scp” to transfer files between hosts, you can try the “sz/rz” commands which use the “ZMODEM“ protocol.
First, install the “lrzsz“ packages on both sides.
Then there are some different approaches to transfer files.
- Use a terminal software which supports the ZMODEM protocol such as “SecureCRT”
In this approach, if you want to upload file to a remote host, you can use SecureCRT to “ssh” to your target host, then execute “rz” command on the target host, then a file Window is opened by SecureCRT, you can select your local file, then the local file you selected will be transfer to the target host. If you want to download file from a remote host, just run “sz FILENAME” on the remote host, and then SecureCRT will open a file window in which you can set where to store the file. After you select the target position to save the file, the transfer will start.
The default gnome-terminal on Ubuntu does not support the ZMODEM protocol like SecureCRT. However you can use zssh to do the same thing.
First, install “zssh”. Under ubuntu execute “sudo apt-get install zssh”.
Use “zssh” command instead of “ssh” to connect to your target host, the arguments are all the same.
If you want to send file from your local host to the remote host, in the zssh terminal navigate to your target directory on the target host, press the hot key “Ctrl + Space”, you will be prompted to execute the zssh commands on your local host, you can use “cd/pwd/ls” to find your local file to be sent, and “sz FILENAME” to start the tranfer.
If you want to download file from the remote host, execute the “sz FILENAME” command on the target host, then press the “Ctrl + Space” hot key to open the zssh prompt, then use “cd/pwd” commands to select the directory to receive the file, then enter”rz” to start the transfer.
The “screen” command support the ZMODEM protocol. Before tranfering file, you need to start “screen” and configure it to “catch” zmodem traffic:
1 | screen -S download |
Then you can use “ssh” in the screen session to login to the remote target host.
If you want to download a file from the remote host, execute “sz FILENAME” on the remote host and press “Enter” when you see the “:!!! rz -vv -b -E” prompt. Then the file will be download your local directory where your start your “ssh” command.
If you want to upload a file to the remote host, execute “rz” on the remote host, you will see a “:!!! sz -vv -b” prompt, now you can input your local file path such as “/home/user/abc.txt” after the prompt and press “Enter”, then your file will be uploaded to the remote host.