Skip to content

Commit

Permalink
add command exists
Browse files Browse the repository at this point in the history
  • Loading branch information
ixqbar committed Sep 20, 2018
1 parent 02a75dc commit c58e73a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

### version
```
v0.0.2
v0.0.3
```

### usage
Expand All @@ -24,6 +24,7 @@ OK
ping {message}
ftpsync {local file} {remote file}
files {remote folder}
exists {remote file}
delete {remote file}
```

Expand Down
2 changes: 1 addition & 1 deletion src/ftpSync/const.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package ftpSync

const VERSION = "0.0.2"
const VERSION = "0.0.3"
17 changes: 17 additions & 0 deletions src/ftpSync/syncFtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,23 @@ func (obj *SyncFtp) DeleteFile(remoteFile string) bool {
return true
}

func (obj *SyncFtp) ExistsFile(remoteFile string) bool {
obj.Lock()
defer obj.Unlock()

if obj.syncFtpServer == nil && obj.connectFtpServer() == false {
return false
}

_, err := obj.syncFtpServer.FileSize(remoteFile)
if err != nil {
Logger.Printf("check ftp server file %s exists failed %v", remoteFile, err)
return false
}

return true
}

func (obj *SyncFtp) Stop() {
if obj.syncFtpServer != nil {
obj.syncStopChannel <- true
Expand Down
12 changes: 12 additions & 0 deletions src/ftpSync/syncServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ func (obj *ftpSyncRedisHandler) Delete(remoteFile string) error {
return nil
}

func (obj *ftpSyncRedisHandler) Exists(remoteFile string) (int, error) {
if len(remoteFile) == 0 || strings.HasPrefix(remoteFile, "/") == false || strings.HasSuffix(remoteFile, "/") == true {
return 0, errors.New("error params")
}

if GSyncFtp.ExistsFile(remoteFile) {
return 1, nil
}

return 0, nil
}

func Run() {
wordsFilterHandler := &ftpSyncRedisHandler{}

Expand Down

0 comments on commit c58e73a

Please sign in to comment.