Topic "Powershell Script and WinSCP"

Author Message
Juneb
[View user's profile]

Joined: 2012-04-03
Posts: 2
Location: U.S.
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

{

}
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
You should better use WinSCP .NET assembly.
There are lots of examples for PowerShell:
http://winscp.net/eng/docs/library#powershell
_________________
Martin Prikryl
Juneb
[View user's profile]

Joined: 2012-04-03
Posts: 2
Location: U.S.
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?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
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.
_________________
Martin Prikryl
namerg

Guest


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)
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
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 http://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.
_________________
Martin Prikryl
Southjam

Guest


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

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License