ftpsync icon indicating copy to clipboard operation
ftpsync copied to clipboard

Do you feel there is something wrong with this code

Open YJiWei opened this issue 4 years ago • 0 comments

//uploadDirectory 遍历上传远程文件夹 func (sftpHandler *SftpHandler) uploadDirectory(localPath string, remotePath string) { //打开本地文件夹流 localFiles, err := ioutil.ReadDir(localPath) if err != nil { log.Fatal("路径错误 ", err) } //先创建最外层文件夹 sftpHandler.SftpClient.Mkdir(remotePath) //遍历文件夹内容 for _, backupDir := range localFiles { localFilePath := path.Join(localPath, backupDir.Name()) remoteFilePath := path.Join(remotePath, backupDir.Name()) //判断是否是文件,是文件直接上传.是文件夹,先远程创建文件夹,再递归复制内部文件 if backupDir.IsDir() { sftpHandler.SftpClient.Mkdir(remoteFilePath) sftpHandler.uploadDirectory(localFilePath, remoteFilePath) } else { sftpHandler.uploadFile(path.Join(localPath, backupDir.Name()), remotePath) } }

mylog.Logger.Println("上传本地目录:" + localPath + "远端目录:" + remotePath)

}

YJiWei avatar Dec 02 '20 08:12 YJiWei