You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How can I perform sftp download and upload feature for multiple files at root directory and within nested subfolder using https://github.com/pkg/sftp
#570
Open
aashakabra opened this issue
Dec 27, 2023
· 3 comments
How can I perform sftp download and upload feature for multiple files at root directory and within nested subfolder using https://github.com/pkg/sftp for wildcards like * , abc?.txt, abc*.txt and so on.
Are there any apis available that will list all the files with specific prefix ?
Also, for implementation of creation of nested folders?
Any reference that can help with this requirement.
I am able to perform the operation using java third party Jsch library and I am looking to do similar implementation in golang.
Thanks,
Asha
The text was updated successfully, but these errors were encountered:
Thanks @puellanivis , above works for files but I am facing error for directory name that matches the pattern.
How will I be able to copy the entire folder as well that matches the pattern?
For example -
folder structure contains a folder named "new" and has two files one.txt and two.txt
my pattern is n*
Code snippet that worked for files is -
paths, _:= sc.Glob("n*")
for i := 0; i < len(paths); i++ {
srcFile, _ := sc.OpenFile(paths[i], (os.O_RDONLY))
defer srcFile.Close()
dstFile, _ := os.Create(filepath.Join(<<LocalFolderPath>>, paths[i])) //created the file name at destination folder same as source file name
defer dstFile.Close()
bytes, _ := io.Copy(dstFile, srcFile)
fmt.Println("bytes copied:", bytes)
}
You will need to use a recursive function that in its body will os.Stat()s the file and if it is a FileInfo.IsDir() you need to then use sftp.Client.ReadDir() to get a listing of the directory and then add those to the list of paths, or just download them directly.
Hello,
How can I perform sftp download and upload feature for multiple files at root directory and within nested subfolder using https://github.com/pkg/sftp for wildcards like * , abc?.txt, abc*.txt and so on.
Currently I have implemented single file transfer from and to sftp server using https://github.com/pkg/sftp
Are there any apis available that will list all the files with specific prefix ?
Also, for implementation of creation of nested folders?
Any reference that can help with this requirement.
I am able to perform the operation using java third party Jsch library and I am looking to do similar implementation in golang.
Thanks,
Asha
The text was updated successfully, but these errors were encountered: