Post a reply

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

martin

Just modify your existing powershell.exe command-line in the batch file.
Vann_the_Red

Excellent. Happy to do so. I don't know if it's the batch file or WinSCP, I'm just trying to figure that out. Where do I add that command? The batch file or the WinSCP script?
Thanks,
VtR
martin

Vann_the_Red wrote:

I thought we were trying to determine why we do not return to the batch file after the script completes. If that is not of interest, we'll just drop it.

If you believe the problem is on WinSCP-side, I'm interested.
In that case, please post the output.
You can capture it by doing something like:
powershell .... > output.txt 2>&1
Vann_the_Red

Martin,
I thought we were trying to determine why we do not return to the batch file after the script completes. If that is not of interest, we'll just drop it.
Thanks for your help,
VtR
martin

That's a log file again. Not a capture of the output.
Anyway, does it matter? Haven't you moved to another solution anyway?
Vann_the_Red

Martin,
Here is the complete (redacted) log from a run of the script. I have only redacted folder locations, IP/ports, and anything that identifies the data partner. I hope I've understood you properly this time.
Regards,
VtR
martin

The script outputs lot of progress messages using Write-Host. I've asked for that output.
Vann_the_Red

Martin,
First, thank you for the correction! I'll put that in place.
Second, I guess I'm confused by what you mean by output. The output of the script is a successful download to the temp directory. What I need to add is a move of that download from the temp folder to the live folder.
Regards,
VtR
martin

I've asked for an output, not for a log file.

Though, as you have switched to PowerShell anyway: Not in finally { }! You want to move the files on success only. So, for example after Write-Host "Done, downloaded $count files.".
Vann_the_Red

Martin,
I've attached the tail of the log from a successful connection. At that point, the batch file exits as well.

For your comment or to help others, here's how I'm planning to modify your script. First, I will add an optional parameter:

param (
    # Use Generate Session URL function to obtain a value for -sessionUrl parameter.
    $sessionUrl = "sftp://user:mypassword;fingerprint=ssh-rsa-xx-xx-xx@example.com/",
    [Parameter(Mandatory = $True)]
    $localPath,
    [Parameter(Mandatory = $True)]
    $remotePath,
    [Parameter(Mandatory = $False)]
    $finalDir,
    [Parameter(Mandatory = $True)]
    $listPath,
    $sessionLogPath = $Null,
    [Switch]
    $pause
)

And then, later:
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
        # Move downloads to the finalDir from parameters
        if ($finalDir) {
          Move-Item -Path $localPath\* -Destination $finalDir
        }
    }


I'm still testing, but I think that should work.
Regards,
VtR
martin

If you need a help regarding your original issue, please post the output.
martin

Re: Batch File or Script Error?

I do not know what your downloadNewFiles.ps1 does. Does it do any logging/progress output? What output do you get, when you execute the batch file? And once you have everything in PowerShell script, you better do the move in the PowerShell script too.
Vann_the_Red

Batch File or Script Error?

Hello, Martin!

I implemented your downloadNewFiles.ps1 script and it works very well. I am downloading to a temp file because the files are huge and my bandwidth is tiny. After the download completes, I want to move the files from the temp directory to an active directory. To do that, I added a simple file move to the batch file. This code, however, is not being executed. I'm not sure if the issue is how the script exits or in the batch file. In my batch files that execute your download and archive script, it is no problem running subsequent commands in the batch file.

Here are the contents of the file:
@echo off
:Start
REM download new data from <location>
powershell.exe -File C:/dtl_ftp/bin/downloadNewFiles.ps1 -sessionURL "sftp://username:password;fingerprint=ssh-rsa redacted=@IP:port/" -localPath "C:/dtl_ftp/Temp/folder/ -remotePath "/" -listPath "c:\dtl_ftp\conf\location_downloaded.txt" -sessionLogPath "C:\dtl_ftp\logs\log.log"
REM push to active folder
move c:\dtl_ftp\Temp\folder\*.* c:\dtl_ftp\Dowloads\folder
:Done
exit


Note that the script executes without error and if I copy the move into a command line, it works fine. But, it is not called in this configuration. Any thoughts are appreciated!

Regards,

VtR