Search code examples
linuxmobaxterm

How to properly upload a local file to a server using mobaXterm?


I'm trying to upload a file from my local desktop to a server and I'm using this command:

scp myFile.txt [email protected]:/opt/nicescada/web

following the structure: scp filename user@ip:/remotePath.

But I get "Permission Denied". I tried using sudo , but I get the same message. I'm being able to download from the server to my local machine, so I assume I have all permissions needed.

What can be wrong in that line of code?


Solution

  • In case your /desired/path on your destination machine has write access only for root, and if you have an account on your destination machine with sudo privileges (super user privileges by prefixing a sudo to your command), you could also do it the following way:

    Option 1 based on scp:

    1. copy the file to a location on your destination machine where you have write access like /tmp:
      scp file user@destinationMachine:/tmp
      
    2. Login to your destination machine with:
      ssh user@destinationMachine
      
    3. Move the file to your /desired/path with:
      sudo mv /tmp/file /desired/path
      

    In case you have a passwordless sudo setup you could also combine step 2. and 3. to

    ssh user@destination sudo mv /tmp/file /desired/path
    

    Option 2 based on rsync

    Another maybe even simpler option would be to use rsync:

    rsync -e "ssh -tt" --rsync-path="sudo rsync" file user@destinationMachine:/desired/path
    

    with -e "ssh -tt" added to run sudo without having a tty.