Powershell to check existance of file on ftp server if iexists send email

chetan Vishwakarma 146 Reputation points
2021-09-08T09:52:11.14+00:00

Hello Team ,

I want to create a powershell script which checks the existence of file on ftp server and if file exists it will send email.

Ex-
below sample details I have received from client.

ftp server detail : sftp.abc.com
Port: 23
Username : user1
Password - xyzxyz

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,576 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 34,686 Reputation points
    2021-09-08T12:10:04.737+00:00

    Here's an example that you can modify.

    $cmds =@("open localhost
    anonymous
    user@foo.com
    dir foo.txt
    quit")
    
    $Response = $cmds | ftp.exe 
    $foo = $Response -match 'foo.txt' 
    if ($foo.count -eq 0) {
        "It's not there"
    } else {
        "We found this..."
        $foo
        "Send your email here."
    }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.