{"id":47,"date":"2015-03-30T14:25:49","date_gmt":"2015-03-30T14:25:49","guid":{"rendered":"https:\/\/hosebei.wordpress.com\/?p=47"},"modified":"2015-03-30T14:25:49","modified_gmt":"2015-03-30T14:25:49","slug":"upload-files-to-ftp-with-powershell","status":"publish","type":"post","link":"https:\/\/blog.hosebei.ch\/?p=47","title":{"rendered":"Upload files to FTP with Powershell"},"content":{"rendered":"<p>Hi,<\/p>\n<p>it took Long, but now, I decided to cut one more VBScript off, and start implementing a Powershell Script to upload the CRL to my CRL Distribtion Point with FTPS, so I took the Script from my collegue (http:\/\/www.thomasmaurer.ch\/2010\/11\/powershell-ftp-upload-and-download\/), and made some &#8220;improvements&#8221;:<br \/>\n<code><br \/>\n#Declare the folder<br \/>\n$Dir=\"\\\\yourserver\\servershare\\\" <\/p>\n<p>#ftp server<br \/>\n$ftpserver = \"ftp:\/\/yourftpserver\/folder\"<br \/>\n$user = \"username\"<br \/>\n$pass = \"corresponding password\"<\/p>\n<p>foreach($item in (Get-ChildItem $Dir -Include \"*.crl\",\"*.crt\",\"*.cer\")){<br \/>\n\"Uploading $item...\"<br \/>\n#connect to ftp server<br \/>\n$ftp = [System.Net.FtpWebRequest]::Create($ftpserver+$item.Name)<br \/>\n$ftp = [System.Net.FtpWebRequest]$ftp<br \/>\n$ftp.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile<br \/>\n$ftp.Credentials = new-object System.Net.NetworkCredential($user,$pass)<br \/>\n$ftp.UseBinary = $true<br \/>\n$ftp.EnableSsl = $true<br \/>\n#$ftp.UsePassive = $false<br \/>\n# read in the file to upload as a byte array<br \/>\n$content = [System.IO.File]::ReadAllBytes($item.FullName)<br \/>\n$ftp.ContentLength = $content.Length<br \/>\n# get the request stream, and write the bytes into it<br \/>\n$rs = $ftp.GetRequestStream()<br \/>\n$rs.Write($content, 0, $content.Length)<br \/>\n# be sure to clean up after ourselves<br \/>\n$rs.Close()<br \/>\n$rs.Dispose()<br \/>\n$ftp.Abort()<br \/>\n$ftp = $null<br \/>\n}<br \/>\n<\/code><\/p>\n<p>Hope this helps \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, it took Long, but now, I decided to cut one more VBScript off, and start implementing a Powershell Script to upload the CRL to my CRL Distribtion Point with FTPS, so I took the Script from my collegue (http:\/\/www.thomasmaurer.ch\/2010\/11\/powershell-ftp-upload-and-download\/), and made some &#8220;improvements&#8221;: #Declare the folder $Dir=&#8221;\\\\yourserver\\servershare\\&#8221; #ftp server $ftpserver = &#8220;ftp:\/\/yourftpserver\/folder&#8221; $user = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"class_list":["post-47","post","type-post","status-publish","format-standard","hentry","category-powershell"],"_links":{"self":[{"href":"https:\/\/blog.hosebei.ch\/index.php?rest_route=\/wp\/v2\/posts\/47","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.hosebei.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hosebei.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hosebei.ch\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hosebei.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=47"}],"version-history":[{"count":0,"href":"https:\/\/blog.hosebei.ch\/index.php?rest_route=\/wp\/v2\/posts\/47\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.hosebei.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=47"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hosebei.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=47"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hosebei.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=47"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}