{"id":5851,"date":"2022-07-13T23:31:29","date_gmt":"2022-07-13T23:31:29","guid":{"rendered":"https:\/\/pariswells.com\/blog\/?p=5851"},"modified":"2022-11-23T10:20:20","modified_gmt":"2022-11-23T10:20:20","slug":"how-to-batch-download-things-via-batpowershell-to-sftp-using-winscp","status":"publish","type":"post","link":"https:\/\/pariswells.com\/blog\/research\/how-to-batch-download-things-via-batpowershell-to-sftp-using-winscp","title":{"rendered":"How to Batch Download  things via Bat\\Powershell to SFTP using WinSCP"},"content":{"rendered":"<div class=\"wp-block-wab-pastacode\">\n\t<div class=\"code-embed-wrapper\"> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">&quot;C:\\Program Files (x86)\\WinSCP\\WinSCP.com&quot; \/script=&quot;C:\\Scripts\\DownloadSFTP.txt&quot;<br\/>if %ERRORLEVEL% neq 0 goto error<br\/> <br\/>echo Download succeeded, Do nothing<br\/><br\/>REM Rename Files to put date on the end , 3 Double Quote each variable as Quotes inside command<br\/>powershell -command &quot;Get-ChildItem &quot;&quot;&quot;\\\\files\\Test*.csv&quot;&quot;&quot; | ren -NewName { &quot;&quot;&quot;$($_.BaseName)$(get-date -format &quot;&quot;&quot;_yyyyMMddhhmmss&quot;&quot;&quot;)$($_.extension) &quot;&quot;&quot;}&quot;<br\/><br\/><br\/>exit \/b 0<br\/> <br\/>:error<br\/>echo Download failed, keeping local files<br\/>exit \/b 1<\/code><\/pre> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Download.bat<\/span> <\/div> <\/div><\/div>\n\n\n<div class=\"wp-block-wab-pastacode\">\n\t<div class=\"code-embed-wrapper\"> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\"><br\/>open sftp:\/\/username:password@sftp.server.com:22\/ <br\/><br\/>#Open Local Folder<br\/>lcd &quot;\\\\files\\download&quot;<br\/><br\/>#Open Remote Folder<br\/>cd outbound<br\/><br\/>#Download all folders and delete when done to not download same files<br\/>get -delete *<br\/><br\/># Exit WinSCP<br\/>exit<\/code><\/pre> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">C:\\Scripts\\DownloadSFTP.txt<\/span> <\/div> <\/div><\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5851","post","type-post","status-publish","format-standard","hentry","category-research"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/5851","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/comments?post=5851"}],"version-history":[{"count":3,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/5851\/revisions"}],"predecessor-version":[{"id":6386,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/5851\/revisions\/6386"}],"wp:attachment":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/media?parent=5851"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/categories?post=5851"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/tags?post=5851"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}