Hello @chetan Vishwakarma
I would like to suggest you to check below Microsoft thread which used WinSCP assembly to check if file exists or not in SFTP.
If the reply was helpful, please don’t forget to upvote or accept as answer.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello Everyone ,
I am new to PowerShell & I want to create a script in PowerShell which checks the file on sftp server and it will send email if file will be there on sftp.
I have checked but didn't found anything , but have some clue that we can call WINSCP dot net assembly through PowerShell to achieve this. Here are the details below i have received from the business
sftp Server name : sftp.xyz.org
username : Test
password : Test@123
port : 22
Only these details I have received from the business side. Could you please create the script for me if possible ?
Thanks in advance !
Br
Chetan
Hello @chetan Vishwakarma
I would like to suggest you to check below Microsoft thread which used WinSCP assembly to check if file exists or not in SFTP.
If the reply was helpful, please don’t forget to upvote or accept as answer.
Download Psftp
https://www.puttygen.com/psftp
Use the sample code that I gave you in your first question to call PsFtp.exe instead of Ftp.exe.
The command line switches will be different, but it should not be that difficult for you to figure out.
C:\>psftp -?
PuTTY Secure File Transfer (SFTP) client
Release 0.74
Usage: psftp [options] [user@]host
Options:
-V print version information and exit
-pgpfp print PGP key fingerprints and exit
-b file use specified batchfile
-bc output batchfile commands
-be don't stop batchfile processing if errors
-v show verbose messages
-load sessname Load settings from saved session
-l user connect with specified username
-P port connect to specified port
-pw passw login with specified password
-1 -2 force use of particular SSH protocol version
-4 -6 force use of IPv4 or IPv6
-C enable compression
-i key private key file for user authentication
-noagent disable use of Pageant
-agent enable use of Pageant
-hostkey aa:bb:cc:...
manually specify a host key (may be repeated)
-batch disable all interactive prompts
-no-sanitise-stderr don't strip control chars from standard error
-proxycmd command
use 'command' as local proxy
-sshlog file
-sshrawlog file
log protocol details to a file
C:\>
I needed to do the same thing and google got me here but did not find any of the answers helpful at all.
This worked for me anyway
Store credentials in Credential Manager as xyz
$cred = Get-StoredCredential -Target xyz;
$SFTPSession = New-SFTPSession -ComputerName sftp.xyz.org -Credential $cred
Test-SFTPPath $SFTPSession "/path/filename.txt"
Remove-SFTPSession -SessionID 0 -Verbose
Get-SFTPSession # just a check to ensure sessions is closed