惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
About on SuperTechFans
Y
Y Combinator Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Security Blog
Microsoft Security Blog
aimingoo的专栏
aimingoo的专栏
I
InfoQ
C
Check Point Blog
IT之家
IT之家
MyScale Blog
MyScale Blog
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
Last Week in AI
Last Week in AI
GbyAI
GbyAI
P
Proofpoint News Feed
量子位
Stack Overflow Blog
Stack Overflow Blog
Microsoft Azure Blog
Microsoft Azure Blog
月光博客
月光博客
阮一峰的网络日志
阮一峰的网络日志
人人都是产品经理
人人都是产品经理
B
Blog
T
The Blog of Author Tim Ferriss
H
Help Net Security
云风的 BLOG
云风的 BLOG

博客园 - stefanie

SQL - 获取多机构最近相同节点 PowerShell-将CSV导入SQL Server [Powershell] 检查IIS设置 VBS 操作注册表 十六进制 无法在People Picker中选择用户 Microsoft Certification List WINDOWS 2012忘记密码之后。。。 Auto Install Workflow Manager 1.0 批量删除Kindle Personal Documents 导入Excel表格到SharePoint站点 用户中心 - 博客园 [PowerShell] Backup Folder and Files Across Network SSRS 请求并显示SharePoint人员和组字段 VS 2010 安装 .net framework2.0/3.0/3.5 How to Setup AssociatedOwnerGroup / AssociatedMemberGroup / AssociatedVisitorGroup RPC服务不可用 [转]SharePoint Versions 安装 64 位版本的 Office 2010 后,无法查看数据表视图中的列表 [MOSS]关闭弹出窗口
[Powershell] FTP Download File
stefanie · 2013-07-17 · via 博客园 - stefanie
 1 # Config
 2 $today = Get-Date -UFormat "%Y%m%d"
 3 $LogFilePath = "d:\ftpLog_$today.txt"
 4 $UserName = "ftpuser"
 5 $Password = "Password01!"
 6 
 7 
 8 function REM($Msg){
 9     $now= Get-Date
10     write-host "$now : $Msg" -foregroundcolor Yellow
11     Add-Content $LogFilePath "$now : $Msg"
12 }
13 
14 function DownloadFile($Username,$Password,$RemoteFile,$LocalFile){
15 
16     try
17     {
18         $ErrorActionPreference="Stop";
19 
20         if($RemoteFile -eq $null){ 
21             REM "RemoteFile is null"
22             return 
23         }
24         if($LocalFile -eq $null){ 
25             REM "LocalFile is null"
26             return 
27         }
28     
29         $FTPRequest = [System.Net.FtpWebRequest]::Create($RemoteFile)
30         $FTPRequest.Credentials = New-Object System.Net.NetworkCredential($Username,$Password) 
31         $FTPRequest.Method = [System.Net.WebRequestMethods+Ftp]::DownloadFile 
32         $FTPRequest.UseBinary = $true
33         $FTPRequest.KeepAlive = $false
34         # Send the ftp request
35         $FTPResponse = $FTPRequest.GetResponse() 
36         # Get a download stream from the server response 
37         $ResponseStream = $FTPResponse.GetResponseStream() 
38         # Create the target file on the local system and the download buffer 
39         $LocalFileFile = New-Object IO.FileStream ($LocalFile,[IO.FileMode]::Create) 
40         [byte[]]$ReadBuffer = New-Object byte[] 1024 
41         if($ResponseStream -eq $null){
42             return
43         }
44         # Loop through the download 
45         do { 
46             $ReadLength = $ResponseStream.Read($ReadBuffer,0,1024) 
47             $LocalFileFile.Write($ReadBuffer,0,$ReadLength) 
48         
49         } 
50         while ($ReadLength -ne 0)
51 
52         REM "$RemoteFile 下载成功。"
53     }
54     catch
55     {
56         REM("Exception Msg: $_")
57     }
58 
59 }
60 
61 
62 
63 DownloadFile $UserName $Password "ftp://192.168.1.103/frate.csv" "c:\downloads\frate.csv"
64 DownloadFile $UserName $Password "ftp://192.168.1.103/bcirfp.csv" "c:\downloads\bcirfp.csv" 

连接Linux机器上的ftp时候,切记文件名是区分大小写滴!