Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try
- {
- # Load WinSCP .NET assembly
- Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
- # Set up session options
- $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
- Protocol = [WinSCP.Protocol]::Sftp
- HostName = "ftp hostname here"
- UserName = "ftp un here"
- Password = "ftp pw here"
- SshHostKeyFingerprint = "ssh fingerprint here"
- }
- $sessionOptions.AddRawSettings("ProxyPort", "0")
- $session = New-Object WinSCP.Session
- #Begin file upload to SFTP destination
- try
- {
- # Connect
- $session.Open($sessionOptions)
- # Transfer files
- $session.PutFiles($File, "/Export/*").Check()
- #move successfully transfered files to a Completed folder
- Move-Item $File -Destination $Destination -Force
- }
- finally #end Try
- {
- $session.Dispose()
- }
- exit 0
- }
- catch #end Try
- {
- Write-Host "Error: $($_.Exception.Message)"
- exit 1
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement