Compare commits

...

3 Commits

Author SHA1 Message Date
Thorsten Sommer
57dcea32ff Bugfix: No Subdirectory 2017-07-02 22:05:55 +02:00
Thorsten Sommer
a57f82a546 Updated 2017-07-02 13:53:45 +02:00
Thorsten Sommer
444efe3d31 Added showHostKey function 2017-07-02 13:45:34 +02:00
4 changed files with 34 additions and 14 deletions

View File

@ -1,9 +1,12 @@
package main
func correctPath(path string) string {
if path[len(path)-1:] == `/` || path[len(path)-1:] == `\` {
// Case: E.g. remote dir = /myfiles/
return path[:len(path)-1]
} else {
// Case: E.g. remote dir = /myfiles
return path
}
}

13
Main.go
View File

@ -3,8 +3,10 @@ package main
import (
"fmt"
"log"
"net"
"os"
"runtime"
"time"
"github.com/SommerEngineering/Sync/Sync"
"github.com/howeyc/gopass"
@ -14,7 +16,7 @@ import (
func main() {
// Show the current version:
log.Println(`Sync v1.3.0`)
log.Println(`Sync v1.3.2`)
// Allow Go to use all CPUs:
runtime.GOMAXPROCS(runtime.NumCPU())
@ -97,6 +99,7 @@ func main() {
ssh.PasswordCallback(Sync.PasswordCallback),
ssh.KeyboardInteractive(Sync.KeyboardInteractiveChallenge),
},
HostKeyCallback: showHostKey(),
}
// Connect to the SSH server:
@ -111,3 +114,11 @@ func main() {
Sync.Synchronise(ssh, supervised, pushOnly, localDir, remoteDir)
log.Println("Synchronising done.")
}
func showHostKey() ssh.HostKeyCallback {
return func(hostname string, remote net.Addr, key ssh.PublicKey) error {
log.Printf("Your server's hostname is %s (%s) and its public key is %s. If this is wrong, please abort the program now! Wait 16 seconds for your check.", hostname, remote.String(), ssh.FingerprintSHA256(key))
time.Sleep(16 * time.Second)
return nil
}
}

View File

@ -2,24 +2,24 @@
This is a simple SFTP synchronisation tool **without** any external dependencies e.g. PuTTY, WinSCP, OpenSSH. Just download the executable which matches your OS and architecture (32 vs. 64 bits) and run it.
## Syntax
Sync provids a few arguments:
- ``localDir`` defines the local directory e.g. ``c:\Users\A\My Documents`` or ``/users/A/My Documents``. If you omit or set it to ``.``, the current working directory gets used.
- ``remoteDir`` is the remote directory e.g. ``/users/A/Sync``.
- ``server`` is the SSH server e.g. ``my-server.com:22``.
- Use ``user`` to set the user's name and ``pwd`` to set the user's password. You can omit the ``pwd``, thus, the program ask for the password on demand.
- With the argument ``supervised`` you can control if the program should ask you for every type of change. The default is the supervised operating mode. In order to disable it, use ``supervised=false``.
- Finnaly, the ``pushOnly`` argument can be used to set the **backup mode**, where all remote changes are ignored. The default is the enabled backup mode. In order to sync changes in both directions, set ``pushOnly=false``.
Sync uses several parameters:
- The `localDir` parameter defines the local directory e.g. `c:\Users\A\My Documents` or `/users/A/My Documents`. If you omit or set it to `.`, the current working directory gets used.
- The `remoteDir` parameter sets the remote directory e.g. `/users/A/Sync`.
- The `server` parameter is the SSH server e.g. `my-server.com:22`.
- Use the `user` parameter to set the user's name and `pwd` to set the user's password. You can omit the `pwd` and the program ask for the password on demand.
- The parameter `supervised` controls if the program should ask you for every type of change. The default is the supervised operating mode. In order to disable it, use `supervised=false`.
- Finnaly, the `pushOnly` argument can be used to set the **backup mode**, where all remote changes are ignored, which is the default. In order to sync changes in both directions, use `pushOnly=false`.
## Features
- The whole code is open source and can be used for any purpose (also commercial)
- If you want, you can compile the code by your own by using the [Go](http://www.golang.org)
- The program just needs very low resources e.g. around 14 MB memory for Microsoft Windows 10 to sync roughly 6000 files. More files need more memory, because the meta information must keep in memory.
- If a connection cannot setup, the program re-tries it
- At the moment, SSHTunnel uses only the password authentication methods. Therefore, it is currently not possible to use e.g. a certificate, etc. Nevertheless, the implementation of this feature is possible.
- The program needs very low resources e.g. around 14 MB of memory on Microsoft Windows 10 to sync roughly 6,000 files. More files need more memory, because the meta information must keep in memory.
- If a connection cannot set up, the program re-tries it.
- At the moment, Sync uses only the password authentication methods. Therefore, it is currently not possible to use e.g. a certificate, etc. Nevertheless, the implementation of this feature is possible.
- The configuration must be provided by using the command-line arguments. It is currently not possible to use e.g. a configuration file.
- You can avoid the password argument if you prefer to provide the password on demand.
- Sync can be used in **backup mode** where all remote changes are ignored or in the **full mode**, where both directions gets synchronised.
- Use the **supervised mode** in order to get the full control
- Sync can be used in **backup mode** where all remote changes are ignored or in the **full mode**, where both directions gets synchronized.
- Use the **supervised mode** in order to get the full control about any change.
## Download
Go and get the latest release from the [release page](https://github.com/SommerEngineering/Sync/releases). Sync use the [SFTP library](https://github.com/pkg/sftp) from Dave Cheney. Thanks very much for the good work!
Go and get the latest release from the [release page](https://github.com/SommerEngineering/Sync/releases). Sync use the [SFTP library](https://github.com/pkg/sftp) from Dave Cheney. Thanks very much for the great work!

View File

@ -7,6 +7,12 @@ import (
func normalisePath(base, path string) string {
result := strings.Replace(path, base, ``, 1)
// Ensure that the path starts with a slash:
if len(result) > 1 && result[0:1] != `/` {
result = filepath.Join(`/`, result)
}
result = filepath.ToSlash(result)
return strings.ToLower(result)
}