简体   繁体   中英

Powershell download files with today's date from FTP server

$today = (get-date).Date  


$dateStr = '{0:yyyyMMdd}' -f $today

New-Item C:\Desktop\test_$dateStr -ItemType directory 

ftp
open
Server Name
UserID
Password
dir
lcd C:\Desktop\test_$dateStr
prompt
binary
mget *$dateStr.txt   
mget *$dateStr.zip  
bye

I am try to download today's txt files and zip files from FTP server. The files are named test_20131001 so I set up as $dateStr but it is not working. FTP server can not find the folder that I create before I enter FTP server. lcd C:\\Desktop\\test_$dateStr does not work...

lcd and mget are interpreted by FTP.exe, not PowerShell. FTP.exe isn't going to understand $dateStr . Take a look at this FTPClient module as one way to automate FTP download in PowerShell.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM