VMware Cloud Community
bradley4681
Expert
Expert

SFTP Transfer of a Report

I have a script that contains a function to FTP the resulting CSV report off to a server, well security went and decided everything needed to be SFTP and I'm not finding much on SFTP in the forums. I've search Google for powershell sftp and it seems all that is available is paid com objects from third parties. Any ideas on creating an SFTP function in powershell/powercli?

$ftp = [http://System.Net.FtpWebRequest|http://System.Net.FtpWebRequest]::Create("ftp://10.10.10.10/VirtualCenter_Source/Full-HostReport.csv")
$ftp = [http://System.Net.FtpWebRequest|http://System.Net.FtpWebRequest]$ftp
$ftp.Method = [http://System.Net.WebRequestMethods+Ftp|http://System.Net.WebRequestMethods+Ftp]::UploadFile
$ftp.Credentials = new-object System.Net.NetworkCredential("USER","U@PASS")
$ftp.UseBinary = $true
$ftp.UsePassive = $true

# read in the file to upload as a byte array
$content = gc -en byte D:\PowerScripts\Full-HostReport.csv
$ftp.ContentLength = $content.Length

# get the request stream, and write the bytes into it
$rs = $ftp.GetRequestStream()
$rs.Write($content, 0, $content.Length)

# be sure to clean up after ourselves
$rs.Close()
$rs.Dispose()

Cheers,

Bradley Sessions

If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".

Cheers! If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
Reply
0 Kudos
0 Replies