Batch File or Script Error?

Advertisement

Vann_the_Red
Joined:
Posts:
14
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:
32,896
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:
14
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)
  • LogSnippet.log (547 Bytes, Private file)

Reply with quote

Advertisement

You can post new topics in this forum