Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

Poulman

Eventually, I used "brute force" searching by repeating the command line, starting from latest directory upwards and when the latest version of the file is found, exit the procedure.
At least winscp is very helpful at this type of search.
The only people is that the ZIP file cannot be opened immediately because it seems to be used by winscp for a fraction of a second, so I'll have to wait a little after downloading each one and before opening them.
Thanks WINSCP. Now I can save lot of time and repeating clicks (good for my mouse too!)
Guest

Well, thanks for the reply but unfortunately I'm not a programmer and I can't understand a bit.
I don't even know what power script is.
Well, I have to accept that it's not achievable,
Thanks anyway...
martin

Re: Find and get a file from unknown remote subdirectory

You cannot do this with WinSCP scripting.

But it's easy with WinSCP .NET assembly, e.g. from a PowerShell script.

Start with this PowerShell script:
https://winscp.net/eng/docs/script_download_most_recent_file#powershell
(which does the same as your WinSCP script).

And replace the simple $directoryInfo = $session.ListDirectory($remotePath) and $directoryInfo.Files with $session.EnumerateRemoteFiles($remotePath, "FILE*.ZIP", [WinSCP.EnumerationOptions]::AllDirectories)
Poulman

Find and get a file from unknown remote subdirectory

Hello all.

It's been a couple of days I'm trying WinSCP.
Till now I've been using FileZilla but it doesn't support command line automation.
My usual tasks are searching for ZIP files by given name in a specific remote folder and its subdirectory.
It's unknown which subdirectory contains the file. For example:
I search for the latest version of file "FILE*.ZIP". The sure subdirectory where the ZIP files are to be searched is like "/main/files" and there might be a "FILE_V1.ZIP" in "/main/files/Jan", a "FILE_V2.ZIP" also in "/main/files/Jan" but a "FILE_V3.ZIP" might be in "/main/files/Mar", which is the latest version of the "FILE*.ZIP" that I'm searching.
The job until now could only be done in Filezilla manually by opening the "file search" window, set in the "/main/files" remote subdirectory and pressing the "search" button. Then I was getting a list of all the "FILE*.ZIP" files found in every subdirectory of every level, chose the latest version and download the file manually (flattening).
With WinSCP I managed to use the "get" command in cmd to download the latest version of a remote file from a specific subdirectory but -of course- there might be an even newest version in another subdirectory of the same or lower level.
The command I'm using is like this:
C:\Users\me\AppData\Local\WinSCP\WinSCP.com /log="C:\Users\me\AppData\Local\WinSCP\WinSCP.log" /ini=nul /command "open ftp://sitename:password8@ip.ip.ip.ip/ -rawsettings ProxyPort=0" "cd /main/files/2018/01-1" "lcd C:\Users\me\Desktop" "get -latest File123*.zip" "exit"

There are "File123_V1" and "File123_V2" in "/main/files/2018/01-1" subdirectory but there is also "File123_V3" in "/main/files/2018/01" subdirectory which is -of course- omitted from the search.
So, could you please direct me how could I search for a file in all subdirectories by giving the part of its name?
Thanks in advance.