Curated Examples
Stream file content over FTP
Use Transferetto to write and read remote FTP content through managed streams.
This pattern is useful when a script should work with remote content incrementally instead of forcing a whole-file upload or download step first.
It is adapted from the source example at Examples/Example22-FTPStream.ps1.
When to use this pattern
- You want to write or read content in chunks.
- The remote file may be inspected before downloading the whole thing.
- A streaming workflow is more natural than a file-based workflow.
Example
Import-Module Transferetto
$ftpClient = Connect-FTP -Server 'ftp.example.com' -Credential (Get-Credential)
$writeStream = Open-FTPStream -Client $ftpClient -RemotePath '/incoming/ftp-stream-demo.txt' -Mode Write
Write-FTPStream -StreamSession $writeStream -Text "first line`n"
Write-FTPStream -StreamSession $writeStream -Text "second line`n"
Sync-FTPStream -StreamSession $writeStream
Close-FTPStream -StreamSession $writeStream
$readStream = Open-FTPStream -Client $ftpClient -RemotePath '/incoming/ftp-stream-demo.txt' -Mode Read
$chunk = Read-FTPStream -StreamSession $readStream -Count 64 -AsText
$chunk
Close-FTPStream -StreamSession $readStream
Disconnect-FTP -Client $ftpClient
What this demonstrates
- opening a managed FTP write stream
- syncing the remote stream explicitly before closing it
- opening a second stream to read remote content back as text