To synchronize files via SFTP, you can use the command line program “rsync” with the following syntax:
rsync -avz -e “ssh -p [port number]” [source directory on local machine] [username]@[server address]:[destination directory on remote machine]
Explanation of the options used:
- a: archive mode, which preserves permissions, ownerships and timestamps
- v: verbose mode, which shows the progress of the synchronization
- z: compression, which reduces the size of the data transferred
- e: specifies the encryption protocol and port used to connect to the remote server
Note: You may need to replace [port number], [username], [server address], [source directory on local machine] and [destination directory on remote machine] with the correct values for your specific case.
For example:
rsync -avz -e “ssh -p 22” /local/path/to/folder/ username@example.com:/remote/path/to/folder/
This command will copy the contents of the local folder at ‘/local/path/to/folder/’ to the remote folder at ‘/remote/path/to/folder/’ on the server ‘example.com’ using the SFTP protocol on port 22.