- martin
Post a reply
Topic review
- martin
Re: how to add logging & use private key option in power shell script
- nezar
Re: how to add logging & use private key option in power shell script
Hi Martin,
Basically, I choose to use the
How can I set the roll-over and size of the log file with this option?
Basically, I choose to use the
$session.SessionLogPath
option.
How can I set the roll-over and size of the log file with this option?
- nezar
Re: how to add logging & use private key option in power shell script
Hi Martin,
Basically I want to log the WinSCP session. To log the file transfer activity.
Basically I want to log the WinSCP session. To log the file transfer activity.
- martin
Re: how to add logging & use private key option in power shell script
What do you want to log? WinSCP session? Or your PowerShell script output?
For private key, use
https://winscp.net/eng/docs/library_sessionoptions#sshprivatekeypath
For private key, use
SessionOptions.SshPrivateKeyPath
:
https://winscp.net/eng/docs/library_sessionoptions#sshprivatekeypath
- nezar
how to add logging & use private key option in power shell script
Thanks for your reply.
In addition, is there an option to control the log file size & roll-over?
Furthermore, can I use a private key instead of clear username & password?
In addition, is there an option to control the log file size & roll-over?
Furthermore, can I use a private key instead of clear username & password?
- MARTiN95
For logging:
Put this at the first 3 lines of your script.
¨
This will create a file at the given path called
Where
Put this at the first 3 lines of your script.
$filedate = Get-Date -f yyyy-MM-dd
Start-Transcript -Path "C:\Log\Log-$Filedate.txt
Cls
This will create a file at the given path called
Log-$filedate
Where
$Filedate
translates into current date in the yyyy-mm-dd
format
- nezar
How to add logging & use private key option in PowerShell script
Hello,
I am using the below PowerShell script for Moving local files to different location after successful upload.
I need to modify it so that it would create a log file and use a private key instead of clear username & password.
What parameters should I use?
Do you have any example?
I am using WinSCP 5.13.4
I am using the below PowerShell script for Moving local files to different location after successful upload.
I need to modify it so that it would create a log file and use a private key instead of clear username & password.
What parameters should I use?
Do you have any example?
I am using WinSCP 5.13.4
param (
$localPath = "C:\temp\upload\*",
$remotePath = "/test/",
$backupPath = "C:\temp\backup\"
)
try
{
# Load WinSCP .NET assembly
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "IP_Address"
UserName = "username"
Password = "password"
SshHostKeyFingerprint = "ssh-rsa 2048 dxV8kkFWYK4ofTfQdquK1f+sMrvA90BOQ3f7tEm+3k9o="
}
$session = New-Object WinSCP.Session
try
{
# Connect
$session.Open($sessionOptions)
# Upload files, collect results
$transferResult = $session.PutFiles($localPath, $remotePath)
# Iterate over every transfer
foreach ($transfer in $transferResult.Transfers)
{
# Success or error?
if ($transfer.Error -eq $Null)
{
Write-Host "Upload of $($transfer.FileName) succeeded, moving to backup"
# Upload succeeded, move source file to backup
Move-Item $transfer.FileName $backupPath
}
else
{
Write-Host "Upload of $($transfer.FileName) failed: $($transfer.Error.Message)"
}
}
}
finally
{
# Disconnect, clean up
$session.Dispose()
}
exit 0
}
catch
{
Write-Host "Error: $($_.Exception.Message)"
exit 1
}