diff --git a/README.md b/README.md index f053507..3c5aa32 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ### version ``` -v0.0.7 +v0.0.8 ``` ### usage @@ -97,7 +97,7 @@ $redis_handle->rawCommand('exists', '/web/images/hello.gif'); ### deps * https://github.com/jonnywang/go-kits/redis -* https://github.com/jlaffaye/ftp +* https://github.com/jonnywang/ftp ### faq * qq群 233415606 \ No newline at end of file diff --git a/src/ftpSync/const.go b/src/ftpSync/const.go index cd531a7..cee5f35 100644 --- a/src/ftpSync/const.go +++ b/src/ftpSync/const.go @@ -1,8 +1,9 @@ package ftpSync -const VERSION = "0.0.7" +const VERSION = "0.0.8" const TRY_CONNECT_FTP_SERVER_MAX_NUM = 3 const DEPEND_PROCESS_TIMEOUT_SECONDS = 30 const SYNC_TO_FTP_MAX_NUM = 3 const SYNC_TO_FTP_AGAINT_LATER_SECONDS = 3 -const CHECK_FTP_CONNECTION_STATE_INTERVAL_SECONDS = 15 \ No newline at end of file +const CHECK_FTP_CONNECTION_STATE_INTERVAL_SECONDS = 15 +const SYNC_TO_FTP_READ_WRITE_TIMEOUT_SECONDS = 60 \ No newline at end of file diff --git a/src/ftpSync/syncFtp.go b/src/ftpSync/syncFtp.go index c3949b5..f102f81 100644 --- a/src/ftpSync/syncFtp.go +++ b/src/ftpSync/syncFtp.go @@ -2,7 +2,7 @@ package ftpSync import ( "errors" - "github.com/jlaffaye/ftp" + "github.com/jonnywang/ftp" "io" "os" "os/exec" @@ -79,6 +79,7 @@ func (obj *SyncFtp) Init() { for { select { case syncFile := <-obj.syncFileChannel: + Logger.Printf("got sync channel file %v", syncFile) obj.Put(syncFile.LocalFile, syncFile.RemoteFile, syncFile.NumberTimes) default: break F @@ -134,6 +135,8 @@ func (obj *SyncFtp) doDependReadyAction() { pid := obj.dependProcess.Pid Logger.Printf("wait depend process pid=%d", pid) obj.dependProcess.Wait() + obj.dependProcess = nil + obj.syncFtpServer = nil Logger.Printf("wait depend process pid=%d success", pid) }() @@ -190,6 +193,8 @@ func (obj *SyncFtp) ftpServerStateIsActive() bool { continue } + fs.SetOpsTimeout(time.Second * SYNC_TO_FTP_READ_WRITE_TIMEOUT_SECONDS) + err = fs.Login(GConfig.FtpServerUser, GConfig.FtpServerPassword) if err != nil { Logger.Printf("login ftp server %s failed %v", GConfig.FtpServerAddress, err) @@ -240,6 +245,8 @@ func (obj *SyncFtp) Put(localFile, remoteFile string, numberTimes int) bool { obj.Lock() defer obj.Unlock() + Logger.Printf("ready to put %s to %s success", localFile, remoteFile) + reader, err := os.Open(localFile) if err != nil { Logger.Printf("open %s failed %v", localFile, err) @@ -298,6 +305,8 @@ func (obj *SyncFtp) Put(localFile, remoteFile string, numberTimes int) bool { } } + Logger.Printf("start sync %s to %s", localFile, remoteFile) + err = obj.syncFtpServer.Stor(remoteFile, reader) if err != nil { Logger.Printf("sync %s to %s failed %v", localFile, remoteFile, err)