Newbie needing some help moving from Filezilla...
Hi Guys,
Appreciate the assistance. I've recently taken over a project/client, part of which involves the automated daily transfer of a few files via FTP. Previously this had been done using Filezilla, however the client has been having problems with the automation and I've decided to ditch it and upon the recommendation of a friend use WinSCP.
I don't have a lot of experience on the scripting side of things, so although I think I've got the gist of things, I'm getting a little hung up on the nitty-gritty of it.
Since scripts already exist which had been used with Filezilla, I'm wondering if these will work. They're relatively simply, small scripts compared to others I've seen as examples, and so that's confusing me a bit.
There are two scripts:
1 - ftptransfer.txt
Login credentials, remote dir setup, multiple put and quit -
2 - transfer.bat
Local Dir setp, Runs FTP based on other script creds, and archives the local files -
Can those be used for the WinSCP script or should I start fresh?
I found this example and modified it, is it all necessary/correct?
Thanks,
G.
Appreciate the assistance. I've recently taken over a project/client, part of which involves the automated daily transfer of a few files via FTP. Previously this had been done using Filezilla, however the client has been having problems with the automation and I've decided to ditch it and upon the recommendation of a friend use WinSCP.
I don't have a lot of experience on the scripting side of things, so although I think I've got the gist of things, I'm getting a little hung up on the nitty-gritty of it.
Since scripts already exist which had been used with Filezilla, I'm wondering if these will work. They're relatively simply, small scripts compared to others I've seen as examples, and so that's confusing me a bit.
There are two scripts:
1 - ftptransfer.txt
Login credentials, remote dir setup, multiple put and quit -
<username> <password> CD Outbox ascii prompt n mput *.* quit
2 - transfer.bat
Local Dir setp, Runs FTP based on other script creds, and archives the local files -
cd C:\Sales ftp -s:C:\Sales\FTP_transfer\ftptransfer <ip address> move *.* C:\Sales\Archive
Can those be used for the WinSCP script or should I start fresh?
I found this example and modified it, is it all necessary/correct?
[Reflection.Assembly]::LoadFrom("WinSCPnet.dll") | Out-Null $sessionOptions = New-Object WinSCP.SessionOptions $sessionOptions.Protocol = [WinSCP.Protocol]::ftp $sessionOptions.HostName = "<IP address>" $sessionOptions.UserName = "<username>" $sessionOptions.Password = "<password>" $sessionOptions.SshHostKeyFingerprint = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" $session = New-Object WinSCP.Session $session.Open($sessionOptions) $localPath = "C:\Sales\" $remotePath = "/Gibraltar/Outbox" $backupPath = "C:\Sales\Archive" $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 {0} succeeded, moving to backup" -f $transfer.FileName) # Upload succeeded, move source file to backup Move-Item $transfer.FileName $backupPath } else { Write-Host ("Upload of {0} failed: {1}" -f $transfer.FileName, $transfer.Error.Message) } } } finally { # Disconnect, clean up $session.Dispose() } exit 0 } catch [Exception] { Write-Host $_.Exception.Message exit 1 }
Thanks,
G.