none
Power Shell File Upload to SFTP with File Existence Check RRS feed

  • Question

  • 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 

    Thursday, June 25, 2020 9:32 AM

All replies

  • You will have to use FTP commands to list the file.

    Test-SFTPPath 


    \_(ツ)_/

    Thursday, June 25, 2020 10:01 AM
  • We have no idea of what you are trying to do.  I suggest starting by reading the help for the CmdLet.  If you cannot understand the help then you will need to learn enough PowerShell to be able to understand the help.


    \_(ツ)_/

    Thursday, June 25, 2020 11:22 AM