0

I'm trying to upload files to Ubuntu server using sftp. I use put -r dir to upload a folder with all its content. When I run the command it gives something like the following:

 Uploading AuthApp/ to /var/www/html/AuthApp remote open("/var/www/html/AuthApp/.DS_Store"): Permission denied
 Uploading of file AuthApp/.DS_Store to /var/www/html/AuthApp/.DS_Store failed!
 remote open("/var/www/html/AuthApp/.gitattributes"): Permission denied     
 Uploading of file AuthApp/.gitattributes to /var/www/html/AuthApp/.gitattributes failed! 
 remote open("/var/www/html/AuthApp/.gitignore"): Permission denied 
 Uploading of file AuthApp/.gitignore to /var/www/html/AuthApp/.gitignore failed!
 remote open("/var/www/html/AuthApp/artisan"): Permission denied
 Uploading of file AuthApp/artisan to /var/www/html/AuthApp/artisan failed! 
 remote open("/var/www/html/AuthApp/composer.json"): Permission denied 
 Uploading of file AuthApp/composer.json to /var/www/html/AuthApp/composer.json failed! 
 remote open("/var/www/html/AuthApp/composer.lock"): Permission denied
 Uploading of file AuthApp/composer.lock to /var/www/html/AuthApp/composer.lock failed! 
 remote open("/var/www/html/AuthApp/CONTRIBUTING.md"): Permission denied
 Uploading of file AuthApp/CONTRIBUTING.md to /var/www/html/AuthApp/CONTRIBUTING.md failed! 
 remote open("/var/www/html/AuthApp/phpunit.xml"): Permission denied 
 Uploading of file AuthApp/phpunit.xml to /var/www/html/AuthApp/phpunit.xml failed! 
 remote open("/var/www/html/AuthApp/readme.md"): Permission denied 
 Uploading of file AuthApp/readme.md to /var/www/html/AuthApp/readme.md failed! 
 remote open("/var/www/html/AuthApp/server.php"): Permission denied
 Uploading of file AuthApp/server.php to /var/www/html/AuthApp/server.php failed!
 Couldn't setstat on "/var/www/html/AuthApp": Permission denied

I tried to change permissions, add user and apache to the group but nothing works. What else am I missing?

3 Answers 3

1

The better method would be for your program to upload to a user owned directory on the server (aka /home/$USER/upload/ and install a cron job in /etc/crontab on the server that copies the files over as the user apache is set to (likely www-data or apache2) into /var/www/html/ -after- making a timestamped backup of the files it is going to overwrite.

  • it would solve your problem
  • it would prevent data loss in case your copy does something nasty.
  • no need to mess with the website settings and /var/www/html/

A directory watcher (see how to put a trigger on a directory ) can do this real-time.

2
  • Is this the way as for the cron job? sorry I might got off topic: 5 * * * * user mv /Uploads/dir /var/www/html/dir I'm scheduling it to run every 5 minutes Sep 18, 2015 at 13:11
  • Indeed that would be "5 past every hour". I would use a script though so you can create some sort of procedure. Or even forget about cron and use a directory watcher (that would make the copy real time ;) )
    – Rinzwind
    Sep 18, 2015 at 14:16
0

The tag sudo runs everything as root, which you need to do to run this so instead of sftp -r dir do sudo sftp -r dir then enter your password. Note that you will need root access to do this If this works, please check it and vote it up, so other people can find this if they need it.

2
  • Doesn't work. What you are suggesting gives permissions to the local device not the server. Thanks anyway Sep 18, 2015 at 12:55
  • @onlyforthis Oh if this is server programming, cd to your server file then do that command
    – David
    Sep 18, 2015 at 13:43
0

I had this problem while publishing my application from JetBrains Rider on Ubuntu server via SFTP. As there is no way to use sudo in this case, the easy solution was to set publish folder ownership for user, specified in ssh connection for SFTP.

sudo chown -R username:username /your-destination-path

Or, if you are already logged in under this user on server:

sudo chown -R $USER:$USER /your-destination-path

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .