I need to delete files matching some pattern (name containing a specific string) from a remote directory on an SFTP server using PS.
Delete files with pattern in remote SFTP directory
2k views Asked by ITE At
2
There are 2 answers
0
Mike Twc
On
You can also try ssh.net library (it's pretty lightweight)
https://github.com/sshnet/SSH.NET
After you build it the base syntax will look like this
Add-Type -Path "path\to\Renci.SshNet.dll"
$conn = New-Object Renci.SshNet.SftpClient -ArgumentList @($HostName, $PortNumber, $UserName, $Password)
$conn.connect()
$files = $conn.ListDirectory("DirName").FullName | where { $_ -like "*.csv"}
$files | foreach { $conn.Delete($_) }
You can also install GitBash, then you'll have ssh command available in your terminal.
Related Questions in POWERSHELL
- PowerShell Linphone Configuration
- How avoid \t being converted to Tab in Powershell
- How do I get my terminal to work in VS Code? Exit Code:2, doesn't allow me to type anything
- Npm command not working in powershell but works in cmd
- Issue with path not being treated as encapsulated when calling cmd /C
- Native command throws error only when I redirect to a variable
- Logic Apps and long running Azure Function (Powershell)
- April fools - PsExec (PsTools)
- How to use nested ForEach-Object
- Batch Script-Powershell MessageBox | How do I set TopMost within PS command line of Batch?
- Execution Stuck at Get-PnPPage if function executed on Button Click
- How can I expand a column from group output?
- How to use expression in regex -replace with capturing group in powershell
- powershell where-object -cnotmatch filter unwanted lines
- How to make Visual Studio 2022 project launch Windows Terminal instead of PowerShell?
Related Questions in SFTP
- Failing to pass a downloaded file-like object from sharepoint using the shareplum and paramiko libraries
- SolarIs 11 VM configure sftp. After restart ssh, the sshd_config file resets?
- Ebay upload CSV: Missing Brand when is already filled, also with MPN
- How to delay preMove for each file detected using SFTP?
- Python SFTP Connection Fabric files.exist does not find the file
- Using Jsch for file transfer from remote to local but file getting deleted on getting input stream
- S3 to SFTP sync operator
- Sftp file transfer using powershell in windows
- How to use pysftp with the -o"HostKeyAlgorithms=+ssh-rsa" -o"PubkeyAcceptedKeyTypes=+ssh-rsa" options?
- Issues with processing large Excel files from SFTP using Roo gem in Rails application
- org.apache.sshd.client.SshClient How to use proxy ? (SFTP)
- How do I force the php function ssh2_sftp() to crash or timeout instead of hanging?
- Download entire folder
- phpseclib fails more than succeeds - php script
- Wildcard(*) SFTP in an expect script?
Related Questions in REMOTE-SERVER
- Deploying a Spring Boot and Angular application on XAMPP on a different server
- Using Jsch for file transfer from remote to local but file getting deleted on getting input stream
- Connect to Remote servers using SSH failed on Windows 11
- Error in opening a application through command prompt when the application is deployed to remote site
- code doesn't work in PyCharm, but work in remote executing
- How to import from py file when running jupyter notebook on a remote server
- Why can I no longer access an external API when I log out of the remote session?
- Running Remote SSH not exiting
- VSCode Devcontainers Port forwarding doesn't work properly on remote server
- Attach Visual Studio Code to docker Container not working
- VScode/WSL: Could not fetch remote environment & Failed to connect to the remote extension host server(Error:WebSocket Close with status code 1006)
- Modifying an Environment Variable remotely with Powershell
- Why do I not get the same result when I run a TAIL command from console of a remote server as when I run the same command from a script on local svr?
- Ubuntu Server Remote Access - Without Port Forwarding or VPN
- Explorer and Source Control don't refresh automatically when working on remote directory
Related Questions in FILEPATTERN
- How to set up SFTPSensor in Airflow to react on any file appearing on the server?
- How can I determine which file filter was matched for a FileSystemWatcher event?
- I need my Control-M File Watcher job to pick up a file having a specific type of file pattern name
- Informatica Cloud (IICS) filename using wildcard
- Prettier - How to ignore certain file types in CLI file patterns?
- How do I loop over all Assets folders and sub folders and get to a list all the prefabs in this folders?
- Java recursively list the files from directory of specific pattern
- Unix command to list all the files and directories in the current directory whose second character is a digit
- FFMPEG multiple file pattern not working in single command
- How do I get mocha to execute tests in all subfolders recursively?
- PHP Glob function to find Controller files
- Delete files with pattern in remote SFTP directory
- Mule changing the file name/extension for storing multiple files after splitter
- .prefs file pattern in android studio
- Regex with a wildcard text string
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
There's no native support for SFTP in PowerShell. You have to use a 3rd party SFTP library.
For example with WinSCP .NET assembly, you can do this:
WinSCP GUI can generate code template for you.
(I'm the author of WinSCP)