Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ftprespsonse = [System.Net.FtpWebResponse]$ftp.GetResponse()
- $username="user"
- $password="pw"
- $ftp = [System.Net.FtpWebRequest]::Create("ftp://xxx.xxx.xxx:{port}/file.txt")
- $ftp = [System.Net.FtpWebRequest]$ftp
- $ftp.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
- $ftp.Credentials = new-object System.Net.NetworkCredential($username,$password)
- $ftp.UseBinary = $true
- $ftp.UsePassive = $true
- $ftp.EnableSsl = $true
- $ftp.KeepAlive = $false
- $ftprespsonse = [System.Net.FtpWebResponse]$ftp.GetResponse()
- $content = [System.IO.File]::ReadAllBytes("c:file.txt")
- $ftp.ContentLength = $content.Length
- try
- {
- $rs = $ftp.GetRequestStream()
- $rs.Write($content, 0, $content.Length)
- 'File Uploaded.'
- Write-Host 'Status code: ' + $ftprespsonse.StatusCode
- Write-Host 'Status descriptionL: ' + $ftprespsonse.StatusDescription
- $ftprespsonse.close()
- $ftp.Abort()
- $rs.Close()
- $rs.Dispose()
- }
- catch [System.Exception]
- {
- 'Upload failed.'
- $ftprespsonse = [System.Net.FtpWebResponse]$ftp.GetResponse()
- Write-Host 'Status code: ' + $ftprespsonse.StatusCode
- Write-Host 'Status descriptionL: ' + $ftprespsonse.StatusDescription
- $ftprespsonse.close()
- $ftp.Abort()
- }
- File Uploaded.
- Status code: + ClosingData
- Status descriptionL: + 226- Transfer complete - acknowledgment message is pending.
- 226- Transfer complete - acknowledgment message is pending.
- 226 Transfer complete (Batch Number = 30009).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement