MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / CopyDirectory

Method CopyDirectory

cli/pkg/common/sshremote.go:242–288  ·  view source on GitHub ↗

复制本地文件夹中的文件到 远程主机对应的目录下

(srcDirPath string, remoteDestDirPath string)

Source from the content-addressed store, hash-verified

240
241// 复制本地文件夹中的文件到 远程主机对应的目录下
242func (instance *SSHRemote) CopyDirectory(srcDirPath string, remoteDestDirPath string) error {
243 remoteDestDirPath = instance.ConvertFilePath(remoteDestDirPath)
244
245 //检测目录正确性
246 if srcInfo, err := os.Stat(srcDirPath); err != nil {
247 return err
248 } else {
249 if !srcInfo.IsDir() {
250 return fmt.Errorf("在本地 %v 不是一个正确的目录!", srcDirPath)
251 }
252 }
253
254 isExist := instance.IsDirExist(remoteDestDirPath)
255 if !isExist {
256 return fmt.Errorf("在远程主机上 %v 不是一个正确的目录!", remoteDestDirPath)
257 }
258
259 err := filepath.Walk(srcDirPath, func(localFilePath string, f os.FileInfo, err error) error {
260 if f == nil {
261 return err
262 }
263 if !f.IsDir() {
264 fielRelativePath := strings.Replace(localFilePath, srcDirPath, "", -1)
265 remoteFilePath := FilePahtJoin4Linux(remoteDestDirPath, fielRelativePath)
266 if instance.IsFileExist(remoteFilePath) {
267 return fmt.Errorf("%v 文件已经存在!", remoteFilePath)
268 }
269 // content, _ := os.ReadFile(localFilePath)
270 /* command := fmt.Sprintf(`echo '%v' >> %v`, content, remoteFilePath)
271 _, err := instance.ExeSSHCommand(command) */
272
273 /* err = instance.CheckAndCreateDir(filepath.Dir(remoteFilePath))
274 if err != nil {
275 instance.Clear(remoteDestDirPath)
276 return err
277 } */
278
279 err = instance.CopyFile(localFilePath, remoteFilePath)
280 if err != nil {
281 instance.Clear(remoteDestDirPath)
282 return err
283 }
284 }
285 return nil
286 })
287 return err
288}
289
290// 获取文件内容
291func (instance *SSHRemote) GetContent(filepath string) string {

Callers

nothing calls this directly

Calls 6

ConvertFilePathMethod · 0.95
IsDirExistMethod · 0.95
IsFileExistMethod · 0.95
CopyFileMethod · 0.95
ClearMethod · 0.95
FilePahtJoin4LinuxFunction · 0.85

Tested by

no test coverage detected