Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ftp via powershell - how to indicate success
- $localfile = "D:ExportTESTING.txt"
- $remotefile = "/TESTING.txt"
- $ftphost = "ftp://ftp.site.com"
- $URI = $ftphost + $remotefile
- $username="USERNAME"
- $password="1234"
- function Get-FTPFile
- ($URI,$localfile,$username,$password){
- $credentials=New-Object System.Net.NetworkCredential
- ($username,$password)
- $ftp=[System.Net.FtpWebRequest]::Create($URI)
- $ftp.Credentials=$credentials
- $ftp.UseBinary=1
- $ftp.KeepAlive=0
- $response=$ftp.GetResponse()
- $responseStream = $response.GetResponseStream()
- $file = New-Object
- IO.FileStream ($localfile,[IO.FileMode]::Create)
- [byte[]]$buffer = New-Object byte[] 1024
- $read = 0
- do{
- $read=$responseStream.Read($buffer,0,1024)
- $file.Write($buffer,0,$read)
- }
- while ($read -ne 0)$file.close()
- }
Add Comment
Please, Sign In to add comment