Script to Iterate through Multiple Folders on a Remote Site

Advertisement

Vann_the_Red
Joined:
Posts:
27
Location:
NC, USA

Script to Iterate through Multiple Folders on a Remote Site

Martin and others,

Thanks to all of you for the help you've provided as I implement WinSCP on my program. Great team on the fora with tremendously helpful information.

I'm attempting to replace a well-worn Python SFTP script we've used for years with WinSCP scripts as Python 2.* has reached end-of-life. The original developer is long gone and I haven't the Python to rewrite the encryption stuff.

What the script does, in a nutshell, is read a config file in the format:
/from/path|c:\download\location

The script then makes it's connection (currently listed in the bat file that calls it, but I've already recreated this using your information and power shell) and iterates through each line downloading any new files (again using your great information) from the first location to the second location.

What I haven't yet located is an example of using a list of locations like this. Could one of you point me that way?

Thanks!

VtR

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,378
Location:
Prague, Czechia

Re: Script to Iterate through Multiple Folders on a Remote Site

Vann_the_Red wrote:

What I haven't yet located is an example of using a list of locations like this.
Sorry, this is too vague. What specific problem do you have? Parsing the configuration file into individual entries/paths? Or using those paths with WinSCP? Are you using WinSCP scripting or WinSCP .NET assembly? Show us your code.

Reply with quote

Vann_the_Red
Joined:
Posts:
27
Location:
NC, USA

Martin,

Yes, I see that was inadaquate. I implemented an example script from your site (https://winscp.net/eng/docs/library_example_remember_downloaded_files) and it works well for a single folder. But, the remote site has 37 folders. So, I could implement that script 37 times, but it seems more elegant to connect once and then iterate through the folders I want (there are more than 37 there, but 37 I want to look at for new files). In the current setup, we use a config file that contains a list of folders in the format:
/from/here/|c:\to\here|c:\list\of\downloaded\files

I'd like to use the same construct. What I was looking for was an example of where such a config file was used. Is that enough information?

Thanks again,

VtR

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,378
Location:
Prague, Czechia

The code stores full paths to the "ListPath". So it should work perfectly, even if you loop over the relevant code for each folder from your configuration file.

The code to loop would start from (including):
Write-Host "Looking for new files..."
and end with (including):
{
    Write-Host "Done, no new files found."
}

Reply with quote

Advertisement

You can post new topics in this forum