Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Power Shell File Upload to SFTP with File Existence Check

$
0
0

HI ,

I have a requirement to upload multiple files to SFTP server from my machine using powershell.i have created the following scripts for the same . the script is working fine . but need to check file existence before upload to SFTP server . 

the following are the script i used for upload 

$username = "UserName"
$password = "Password" | ConvertTo-SecureString -AsPlainText -Force
$server = "xxxxx"
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList    $username,$password
Get-SFTPSession | Remove-SFTPSession
$SFTPSession=New-SFTPSession -ComputerName $server -Credential $credential -Port xxxx
$FilePath = get-childitem "D:\Test\xx*"
$SftpPath = '/D:/xxx/xxx/Test'

 ForEach ($LocalFile in $FilePath)
{
Set-SFTPFile -SessionId $SFTPSession.SessionID -LocalFile $LocalFile.fullname -RemotePath $SftpPath -Overwrite
}

Please any body advice me on to check  multiple files existence before uploading and only upload files which is not exist in server .

Thanks in advance 


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>