- martin
Post a reply
Topic review
- npoinard
Hello martin,
Initial I've a cmd file:
The PowerShell launched is formatted like that,
I've some instability on the network and get the timeout when I try to connect
It would like that "Error: Network error: Connection to "*******-******.com" timed out. " in a txt file,
I'll user it has flag file to retry the connection if it's failed.
Initial I've a cmd file:
Cd D:\SFTP
date /t > \\IP-ADRESS\d$\SFTP_Bloomberg_BTCA\SFTP.txt
time /t >> \\IP-ADRESS\d$\SFTP\SFTP.txt
powershell.exe "\\IP-ADRESS\d$\SFTP\sftp.ps1" >> \\IP-ADRESS\d$\SFTP\SFTP.txt
move \\IP-ADRESS\d$\SFTP\PROD\*.csv \\IP-ADRESS\d$\SFTP\PROD\archive\ >> \\IP-ADRESS\d$\SFTP\SFTP.txt
del /f \\IP-ADRESS\d$\SFTP\PROD\*.csv >> \\IP-ADRESS\d$\SFTP\SFTP.txt
date /t >> \\IP-ADRESS\d$\SFTP\SFTP.txt
time /t >> \\IP-ADRESS\d$\SFTP\SFTP.txt
The PowerShell launched is formatted like that,
try
{
# Load WinSCP .NET assembly
Add-Type -Path "D:\SFTP\WinSCPnet.dll"
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "url"
UserName = "user"
SshPrivateKeyPath = "D:\SFTP\private.ppk"
PrivateKeyPassphrase = "pass"
GiveUpSecurityAndAcceptAnySshHostKey = "true"
}
$session = New-Object WinSCP.Session
try
{
$session.SessionLogPath = "D:\SFTP\winscp-upload.log"
# Connect
$session.Open($sessionOptions)
# Upload files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::Off
$transferOptions.FilePermissions = $Null
$transferOptions.PreserveTimestamp = $False
$transferResult = $session.PutFiles("D:\SFTP\prod\*.csv", "/", $False, $transferOptions)
# Throw on any error
$transferResult.Check()
# Print results
foreach ($transfer in $transferResult.Transfers)
{
Write-Host ("Upload of {0} succeeded" -f $transfer.FileName)
}
}
finally
{
# Disconnect, clean up
$session.Dispose()
}
exit 0
}
catch [Exception]
{
Write-Host ("Error: {0}" -f $_.Exception.Message)
exit 1
}
I've some instability on the network and get the timeout when I try to connect
It would like that "Error: Network error: Connection to "*******-******.com" timed out. " in a txt file,
I'll user it has flag file to retry the connection if it's failed.
- martin
Re: Output file when error
I'm not sure I understand.
Are you looking for this?
How do I know that script completed successfully?
Are you looking for this?
How do I know that script completed successfully?
- npoinard
Output file when error
Hello,
sorry if my question has been already asked, I haven't found it.
I've in my SFTP script, an time out error
I would like to have an .txt file when I got this error.
Then I could make a check on the présence of this file.
Thanks in advance
Nicolas.
sorry if my question has been already asked, I haven't found it.
I've in my SFTP script, an time out error
Error: Network error: Connection to "*******-******.com" timed out.
I would like to have an .txt file when I got this error.
Then I could make a check on the présence of this file.
Thanks in advance
Nicolas.