Differences
This shows you the differences between the selected revisions of the page.
script_download_files_to_same_folder 2017-05-15 | script_download_files_to_same_folder 2024-07-19 (current) | ||
Line 1: | Line 1: | ||
- | ====== Download all files to the same local folder ====== | + | ====== Downloading all files from FTP/SFTP to the same local folder ====== |
When downloading a remote directory tree, WinSCP recreates an equivalent tree locally. | When downloading a remote directory tree, WinSCP recreates an equivalent tree locally. | ||
Line 13: | Line 13: | ||
$mask = "*.txt" | $mask = "*.txt" | ||
- | $files = $session.EnumerateRemoteFiles($remotePath, $mask, [WinSCP.EnumerationOptions]::None) | + | $files = $session.EnumerateRemoteFiles( |
+ | ·············$remotePath, $mask, [WinSCP.EnumerationOptions]::AllDirectories) | ||
foreach ($fileInfo in $files) | foreach ($fileInfo in $files) | ||
{ | { | ||
- | Write-Host ("Downloading {0} ..." -f $fileInfo.FullName) | + | Write-Host "Downloading $($fileInfo.FullName) ..." |
- | $session.GetFiles($session.EscapeFileMask($fileInfo.FullName), $localPath + "\*").Check() | + | $filePath = [WinSCP.RemotePath]::EscapeFileMask($fileInfo.FullName) |
+ | $session.GetFiles($filePath, $localPath + "\*").Check() | ||
} | } | ||
</code> | </code> | ||
- | ===== Using WinSCP scripting ===== | + | ===== [[script]] Using WinSCP scripting ===== |
It is too complicated to implement this task with a simple [[scripting]]. If you do not want to use the .NET assembly, you can at least download the remote directory tree as is, and then flatten it locally: | It is too complicated to implement this task with a simple [[scripting]]. If you do not want to use the .NET assembly, you can at least download the remote directory tree as is, and then flatten it locally: | ||
Line 34: | Line 37: | ||
"exit" | "exit" | ||
for /r "%TMPPATH%" %%f in ("*.*") do move "%%f" "C:\local\path\" | for /r "%TMPPATH%" %%f in ("*.*") do move "%%f" "C:\local\path\" | ||
- | rd /s /q "%TMPPATH%" | + | rmdir /s /q "%TMPPATH%" |
</code> | </code> | ||