Batch File or Script Error?

Advertisement

Vann_the_Red
Joined:
Posts:
27
Location:
NC, USA

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

Reply with quote

Advertisement

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

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.

Reply with quote

Vann_the_Red
Joined:
Posts:
27
Location:
NC, USA

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
  • LogSnippet.log (547 Bytes, Private file)

Reply with quote

Advertisement

martin
Site Admin
martin avatar

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.".

Reply with quote

Vann_the_Red
Joined:
Posts:
27
Location:
NC, USA

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

Reply with quote

Vann_the_Red
Joined:
Posts:
27
Location:
NC, USA

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
  • LogSnippet.log (189.8 KB, Private file)

Reply with quote

Advertisement

martin
Site Admin
martin avatar

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

Reply with quote

Vann_the_Red
Joined:
Posts:
27
Location:
NC, USA

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

Reply with quote

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

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

Reply with quote

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

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum