Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Set the credentials
- $Password = ConvertTo-SecureString 'Password1' -AsPlainText -Force
- $Credential = New-Object System.Management.Automation.PSCredential ('root', $Password)
- # Set local file path, SFTP path, and the backup location path which I assume is an SMB path
- $FilePath = "C:FileDumptest.txt"
- $SftpPath = '/Outbox'
- $SmbPath = '\filer01Backup'
- # Set the IP of the SFTP server
- $SftpIp = '10.209.26.105'
- # Load the Posh-SSH module
- Import-Module C:TempPosh-SSH
- # Establish the SFTP connection
- New-SFTPSession -ComputerName $SftpIp -Credential $Credential
- # Upload the file to the SFTP path
- Set-SFTPFile -SessionId 0 -LocalFile $FilePath -RemotePath $SftpPath
- # Disconnect SFTP session
- (Get-SFTPSession -SessionId 0).Disconnect()
- # Copy the file to the SMB location
- Copy-Item -Path $FilePath -Destination $SmbPath
- # Load WinSCP .NET assembly
- Add-Type -Path "WinSCPnet.dll"
- # Setup session options
- $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
- Protocol = [WinSCP.Protocol]::Sftp
- HostName = "example.com"
- UserName = "user"
- Password = "mypassword"
- SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
- }
- $session = New-Object WinSCP.Session
- try
- {
- # Connect
- $session.Open($sessionOptions)
- # Upload
- $session.PutFiles("C:FileDumpexport.txt", "/Outbox/").Check()
- }
- finally
- {
- # Disconnect, clean up
- $session.Dispose()
- }
- pscp -sftp -pw passwd c:filedump* user@host:/Outbox/
- mv c:filedump* c:backup*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement