Guest User

Untitled

a guest
Sep 17th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. ftp via powershell - how to indicate success
  2. $localfile = "D:ExportTESTING.txt"
  3. $remotefile = "/TESTING.txt"
  4. $ftphost = "ftp://ftp.site.com"
  5. $URI = $ftphost + $remotefile
  6. $username="USERNAME"
  7. $password="1234"
  8. function Get-FTPFile
  9. ($URI,$localfile,$username,$password){
  10. $credentials=New-Object System.Net.NetworkCredential
  11. ($username,$password)
  12. $ftp=[System.Net.FtpWebRequest]::Create($URI)
  13. $ftp.Credentials=$credentials
  14. $ftp.UseBinary=1
  15. $ftp.KeepAlive=0
  16. $response=$ftp.GetResponse()
  17. $responseStream = $response.GetResponseStream()
  18. $file = New-Object
  19. IO.FileStream ($localfile,[IO.FileMode]::Create)
  20. [byte[]]$buffer = New-Object byte[] 1024
  21. $read = 0
  22. do{
  23. $read=$responseStream.Read($buffer,0,1024)
  24. $file.Write($buffer,0,$read)
  25. }
  26. while ($read -ne 0)$file.close()
  27. }
Add Comment
Please, Sign In to add comment