For my integration tests, I am running an sftp server (atmoz/sftp) via dockertest. Currently I am mounting a directory (with sub-folders + files)
fp, err := filepath.Abs("./testfixtures/upload")
if err != nil {
return nil, fmt.Errorf("Could not get absolute path: %w", err)
}
options := &dockertest.RunOptions{
Repository: "atmoz/sftp",
Tag: "latest",
Env: []string{
"SFTP_USERS=foo:123:1001:1001",
},
Mounts: []string{
fmt.Sprintf("%s/:/home/foo/upload", fp),
},
}
// Run the container
resource, err := pool.RunWithOptions(options)
if err != nil {
return nil, fmt.Errorf("Could not start resource: %w", err)
}
When connecting to the server in the code, I am able to access the read the files – but NOT rename a file which is a requirement
{"level":"info","timestamp":"2024-08-01T08:39:27.888+0100","caller":"service/service.go:124","msg":"successfully connected to sftp server","hostname":"UK-CTP-LA3053","pip_id":"8cf30e5b-992b-4836-a1a6-e2457cd19d14"}
{"level":"info","timestamp":"2024-08-01T08:39:27.889+0100","caller":"service/service.go:197","msg":"entry found","hostname":"UK-CTP-LA3053","pip_id":"8cf30e5b-992b-4836-a1a6-e2457cd19d14","mode":2147484141,"path":"/","name":"/","size":4096,"mod_time":"2024-08-01T08:39:26.000+0100","is_dir":true}
{"level":"info","timestamp":"2024-08-01T08:39:27.892+0100","caller":"service/service.go:197","msg":"entry found","hostname":"UK-CTP-LA3053","pip_id":"8cf30e5b-992b-4836-a1a6-e2457cd19d14","mode":2147484141,"path":"/upload","name":"upload","size":4096,"mod_time":"2024-07-19T12:24:32.000+0100","is_dir":true}
{"level":"info","timestamp":"2024-08-01T08:39:27.894+0100","caller":"service/service.go:197","msg":"entry found","hostname":"UK-CTP-LA3053","pip_id":"8cf30e5b-992b-4836-a1a6-e2457cd19d14","mode":2147484141,"path":"/upload/incoming","name":"incoming","size":4096,"mod_time":"2024-08-01T08:39:11.000+0100","is_dir":true}
{"level":"info","timestamp":"2024-08-01T08:39:27.896+0100","caller":"service/service.go:197","msg":"entry found","hostname":"UK-CTP-LA3053","pip_id":"8cf30e5b-992b-4836-a1a6-e2457cd19d14","mode":493,"path":"/upload/incoming/G0731626.cdf","name":"G0731626.cdf","size":12,"mod_time":"2024-07-19T08:57:08.000+0100","is_dir":false}
{"level":"info","timestamp":"2024-08-01T08:39:27.896+0100","caller":"service/service.go:197","msg":"entry found","hostname":"UK-CTP-LA3053","pip_id":"8cf30e5b-992b-4836-a1a6-e2457cd19d14","mode":2147484141,"path":"/upload/error","name":"error","size":4096,"mod_time":"2024-07-18T13:33:35.000+0100","is_dir":true}
{"level":"info","timestamp":"2024-08-01T08:39:27.898+0100","caller":"service/service.go:197","msg":"entry found","hostname":"UK-CTP-LA3053","pip_id":"8cf30e5b-992b-4836-a1a6-e2457cd19d14","mode":2147484141,"path":"/upload/archive","name":"archive","size":4096,"mod_time":"2024-07-18T13:33:27.000+0100","is_dir":true}
{"level":"info","timestamp":"2024-08-01T08:39:27.901+0100","caller":"service/service.go:209","msg":"searching for files in directory. current working directory - /. target directory - /upload/incoming","hostname":"UK-CTP-LA3053","pip_id":"8cf30e5b-992b-4836-a1a6-e2457cd19d14"}
{"level":"info","timestamp":"2024-08-01T08:39:27.903+0100","caller":"service/service.go:217","msg":"files found in directory","hostname":"UK-CTP-LA3053","pip_id":"8cf30e5b-992b-4836-a1a6-e2457cd19d14","file_count":1}
{"level":"info","timestamp":"2024-08-01T08:39:27.903+0100","caller":"service/service.go:223","msg":"renaming file G0731626.cdf (493) to G0731626.cdf for archiving process","hostname":"UK-CTP-LA3053","pip_id":"8cf30e5b-992b-4836-a1a6-e2457cd19d14"}
service_test.go:57: failed to process: unable to rename file - G0731626.cdf: sftp: "Failure" (SSH_FX_FAILURE)
I get that this is related to the file mode 493 for the file named G0731626_20240502_022401SB_000001.cdf. But not sure how to resolve this? I can’t change the mode or owner of the local directory as this will prevent the initial mounting.
Any help would be appreciated