Julio Rodriguez
Julio Rodriguez

Reputation: 515

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?

Upvotes: 1

Views: 15341

Answers (2)

Wolfson
Wolfson

Reputation: 1407

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.

Upvotes: 3

VonC
VonC

Reputation: 1323115

Try and specify the full destination path:

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

Of course, double-check cooluser has the right to write (not just read) in that folder: 755, not 644 for the web parent folder.

Upvotes: 2

Related Questions