Short answer – Not possible.
Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | No |
Requirements | rsync |
Time | N/A |
Long answer
The scp command will always overwrite the already present files if owner has write permissions. I suggest that you use the rsync command. The syntax is
rsync --ignore-existing file1 user@server1:/dest/ rsync --ignore-existing file.to.upload user@server1.cyberciti.biz:/path/to/dest/ ### add ssh, just in case ;) ### rsync -e ssh --ignore-existing file.to.upload user@server1.cyberciti.biz:/path/to/dest/ rsync -avP --ignore-existing *.png user@server1.cyberciti.biz:/stoage/static/c/cyberciti.biz/images/ rsync --ignore-existing file1 /path/to/dest/
The --ignore-existing option skip updating files that exist on receiver such as server1.cyberciti.biz.
Shell script example
The following script will upload files from your computer to the remote server using the rsync command. First, make sure you setup the public key authentication:
#!/bin/bash # Purpose: Batch file uploader from my desktop to the remote server # Author: nixCraft <www.cyberciti.biz> under GPL v2.x+ # ----------------------------------------------------------------- _server="server1.cyberciti.biz" _user="nixcraft" ## static url mapping ## _cdnbase="http://static.cyberciti.org/images" _dest="/var/www/images/" _cdnurls="" _isuploaded=0 _files="$@" ## rsync args ## _args="-aPv --ignore-existing" ## fail safe ## [[ "$_files" == "" ]] && { echo "Usage: $0 file1.png file2.png"; exit 0; } ## Let us start uploading files. Bash for loop allows us to do a few more additional things, ## but I am keeping it simple here for demo purpose for i in $_files do # make sure $i file exist # if [ -f "$i" ] then rsync "$_args" "$i" ${_user}@${_server}:${_dest} _cdnurls="${_cdnurls}\n${_cdnbase}/${i##*/}" _isuploaded=1 else echo "Error $i file not found." fi done if [ $_isuploaded -eq 1 ] then echo "CDN urls:" echo -e "$_cdnurls" echo fi
You can use the script as follows:
./script foo.png ./script foo.png bar.png ./script *.mov ./script test.gif
Sample outputs:
sending incremental file list test-image.gif 950 100% 0.00kB/s 0:00:00 (xfer#1, to-check=0/1) sent 1053 bytes received 31 bytes 197.09 bytes/sec total size is 950 speedup is 0.88 CDN urls: http://static.cyberciti.org/images/test-image.gif
Run it again:
./script test.gif
Sample outputs:
sending incremental file list sent 60 bytes received 12 bytes 13.09 bytes/sec total size is 950 speedup is 13.19 CDN urls: http://static.cyberciti.org/images/test-image.gif
See also
If anyone knows a better solution to this FAQ please share in the comments below.
🐧 Please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 2 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
use rsync
mount the resource using sshfs and use regular file manager (if you do stuff manually)