Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

copy/move files on remote server linux

I log into server_a and run .sh file, which has the following script:

scp user@server_b:/my_folder/my_file.xml user@server_b:/my_new_folder/

to copy files from my_folder to my_new_folder at server_b. It doesn't throw an error, but no files are copied.

Notes:

  • server_b is accessed by the pre-set rsa_keys.
  • server_a: unix
  • server_b: ubuntu
  • can SCP files from/to these servers without any issues

The end goal is to move or copy/remove files.

like image 555
D Root Avatar asked Apr 10 '26 14:04

D Root


1 Answers

There are two possibilities:

  1. Connect from server_a to server_b and do local copy:

    ssh user@server_b "cp /my_folder/my_file.xml /my_new_folder/"
    
  2. Do copy over the server_a. Your method would require the server_b to be able to authenticate to itself, which is probably not the case:

    scp -3 user@server_b:/my_folder/my_file.xml user@server_b:/my_new_folder/
    

Also note that your code copies only one file and not files as you write in the title.

like image 104
Jakuje Avatar answered Apr 12 '26 07:04

Jakuje



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!