Powershell Script and WinSCP

Advertisement

Juneb
Joined:
Posts:
2
Location:
U.S.

Powershell Script and WinSCP

Hi All -

I was wondering if i could get some assistance with a powershell/winscp script I am building. It will run in task scheduler every hour, daily, between a certain time slot. The script works - meaning it connects to the remote site and downloads the file(s). What I need, or would like is to pull the file names that were downloaded from the log file created by winscp, and have the names in the email body. Below is the sample script...any help is appreciated.





Clear-Host

$date = Get-Date -format "yyyy-MM-dd HH"
$BaseDir = "SomePath\"
$FileDir = "SomePath\"

Set-location $BaseDir

# Get File - Time Set in Task Scheduler
.\WinSCP.exe /console username@somewhere.com /script=Script.txt /Log=LogFiles/Log-$Date.log
Sleep 120

# Check if File(s) Exists After Download completes
$File = Get-ChildItem "SomePath\*.txt" | where {$_.LastWriteTime.Date -eq ($Date)}
$Checkfile = test-path $File

Get-Content Log-$Date.log

If ($Checkfile -eq $True)

{
Send-MailMessage -To "someone" -From "someone" -Subject "The File Has Downloaded" -SmtpServer "10.10.10.10"

}

else

{

}

Reply with quote

Advertisement

Juneb

Re: Powershell Script and WinSCP

Thanks, I noticed the assemblies after i published the forum note. We are running 4.2.9 of winscp at the moment. Is the .Net Assemblies available with 4.2.9, or just the later versions of winscp?

Reply with quote

martin
Site Admin
martin avatar

Re: Powershell Script and WinSCP

Juneb wrote:

Thanks, I noticed the assemblies after i published the forum note. We are running 4.2.9 of winscp at the moment. Is the .Net Assemblies available with 4.2.9, or just the later versions of winscp?
Just 5.x.

Reply with quote

namerg
Guest

Could not load file or assembly

Hello,
I am trying to upload a file to an ftp site using winscp 5.1.5 through PowerShell but get the following error:
Could not load file or assembly 'WinSCP.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

Reply with quote

Advertisement

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

Re: Could not load file or assembly

namerg wrote:

Hello,
I am trying to upload a file to an ftp site using winscp 5.1.5 through PowerShell but get the following error:
Could not load file or assembly 'WinSCP.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
See https://winscp.net/forum/viewtopic.php?t=12006
If it does not help, please continues on that topic. This topic is not relevant to your problem.

Reply with quote

Southjam
Guest

Re: Could not load file or assembly

namerg wrote:

Hello,
I am trying to upload a file to an ftp site using winscp 5.1.5 through PowerShell but get the following error:
Could not load file or assembly 'WinSCP.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

you have to add the path to where the dll is located.
# Load WinSCP .NET assembly
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
this is for a 64 bit machine of course.

Reply with quote

Advertisement

You can post new topics in this forum