Closed Aquarian-Age closed 3 years ago
A recursive process of sftp.ReadDir
to list the files in the root, and then either: an os.Mkdir
of the subdirectory, followd by a recursive call on the subdirectory; or an r, err := sftp.Open()
with a parallel-filename w, err := os.Create()
followed by a io.Copy(w, r)
and closing the files. The details are left super vague here, because this is a library for providing API access to SFTP.
If you just want to copy the files, I would use scp -r remotehost:dir .
or some other readdy-made tool already available to do so… there really isn’t much a need for you to roll your own.
A recursive process of
sftp.ReadDir
to list the files in the root, and then either: anos.Mkdir
of the subdirectory, followd by a recursive call on the subdirectory; or anr, err := sftp.Open()
with a parallel-filenamew, err := os.Create()
followed by aio.Copy(w, r)
and closing the files. The details are left super vague here, because this is a library for providing API access to SFTP.If you just want to copy the files, I would use
scp -r remotehost:dir .
or some other readdy-made tool already available to do so… there really isn’t much a need for you to roll your own.
Thanks Reply scp works well in linux but cannot be used in windows7 system So I wrote a simple file transfer function
For windows I would recomment PuTTY which has a pscp
binary that does scp
on Windows.
There are the following sample directories
How can I download it locally to keep the directory and files unchanged?