Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. $ftprespsonse = [System.Net.FtpWebResponse]$ftp.GetResponse()
  2.  
  3. $username="user"
  4. $password="pw"
  5. $ftp = [System.Net.FtpWebRequest]::Create("ftp://xxx.xxx.xxx:{port}/file.txt")
  6. $ftp = [System.Net.FtpWebRequest]$ftp
  7. $ftp.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
  8. $ftp.Credentials = new-object System.Net.NetworkCredential($username,$password)
  9. $ftp.UseBinary = $true
  10. $ftp.UsePassive = $true
  11. $ftp.EnableSsl = $true
  12. $ftp.KeepAlive = $false
  13. $ftprespsonse = [System.Net.FtpWebResponse]$ftp.GetResponse()
  14. $content = [System.IO.File]::ReadAllBytes("c:file.txt")
  15. $ftp.ContentLength = $content.Length
  16. try
  17. {
  18. $rs = $ftp.GetRequestStream()
  19. $rs.Write($content, 0, $content.Length)
  20. 'File Uploaded.'
  21. Write-Host 'Status code: ' + $ftprespsonse.StatusCode
  22. Write-Host 'Status descriptionL: ' + $ftprespsonse.StatusDescription
  23. $ftprespsonse.close()
  24. $ftp.Abort()
  25. $rs.Close()
  26. $rs.Dispose()
  27. }
  28. catch [System.Exception]
  29. {
  30. 'Upload failed.'
  31. $ftprespsonse = [System.Net.FtpWebResponse]$ftp.GetResponse()
  32. Write-Host 'Status code: ' + $ftprespsonse.StatusCode
  33. Write-Host 'Status descriptionL: ' + $ftprespsonse.StatusDescription
  34. $ftprespsonse.close()
  35. $ftp.Abort()
  36. }
  37.  
  38. File Uploaded.
  39. Status code: + ClosingData
  40. Status descriptionL: + 226- Transfer complete - acknowledgment message is pending.
  41. 226- Transfer complete - acknowledgment message is pending.
  42. 226 Transfer complete (Batch Number = 30009).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement