# Config
$today = Get-Date -UFormat "%Y%m%d"
$LogFilePath = "d:\ftpLog_$today.txt"
$UserName = "ftpuser"
$Password = "Password01!" function REM($Msg){
$now= Get-Date
write-host "$now : $Msg" -foregroundcolor Yellow
Add-Content $LogFilePath "$now : $Msg"
} function DownloadFile($Username,$Password,$RemoteFile,$LocalFile){ try
{
$ErrorActionPreference="Stop"; if($RemoteFile -eq $null){
REM "RemoteFile is null"
return
}
if($LocalFile -eq $null){
REM "LocalFile is null"
return
} $FTPRequest = [System.Net.FtpWebRequest]::Create($RemoteFile)
$FTPRequest.Credentials = New-Object System.Net.NetworkCredential($Username,$Password)
$FTPRequest.Method = [System.Net.WebRequestMethods+Ftp]::DownloadFile
$FTPRequest.UseBinary = $true
$FTPRequest.KeepAlive = $false
# Send the ftp request
$FTPResponse = $FTPRequest.GetResponse()
# Get a download stream from the server response
$ResponseStream = $FTPResponse.GetResponseStream()
# Create the target file on the local system and the download buffer
$LocalFileFile = New-Object IO.FileStream ($LocalFile,[IO.FileMode]::Create)
[byte[]]$ReadBuffer = New-Object byte[] 1024
if($ResponseStream -eq $null){
return
}
# Loop through the download
do {
$ReadLength = $ResponseStream.Read($ReadBuffer,0,1024)
$LocalFileFile.Write($ReadBuffer,0,$ReadLength) }
while ($ReadLength -ne 0) REM "$RemoteFile 下载成功。"
}
catch
{
REM("Exception Msg: $_")
} } DownloadFile $UserName $Password "ftp://192.168.1.103/frate.csv" "c:\downloads\frate.csv"
DownloadFile $UserName $Password "ftp://192.168.1.103/bcirfp.csv" "c:\downloads\bcirfp.csv"

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

最新文章

  1. Python正则表达式:最短匹配
  2. java.lang.Comparable<T> 接口
  3. Hibernate反向工程生成DAO
  4. Certificate、Provisioning Profile、App ID
  5. android 弹出日期选择框
  6. virtualbox安装centos6.5碰到的问题
  7. 修改dbwr后台进程数量
  8. qt widget设置Qt::FramelessWindowHint和Qt::WA_TranslucentBackground, 会出现一个bug: 在最小化后还原时界面停止刷新
  9. UVa10635 - Prince and Princess(LCS转LIS)
  10. 2016沈阳网络赛 odd-even number
  11. 归并排序Java实现
  12. python在windows下使用setuptools安装egg文件
  13. 超强js博客值得学习!!!
  14. mysql 从一个表中查数据,插入另一个表
  15. Makefile工程管理器及万能模板
  16. JavaScript中的原型链原理
  17. Git中撤销提交
  18. bootstrap使用之多个弹窗和拖动效果[开发篇]
  19. process_begin: CreateProcess(NULL,......) make (e=87): 参数错误。
  20. Expo大作战(三十三)--expo sdk api之MapView(地图),MailComposer(磁力传感计),Lottie(动画)

热门文章

  1. Android实现摇晃手机的监听
  2. Linux中部署JAVA程序
  3. Display number of replies in disscussion board
  4. <php>PDO用法二
  5. hdu 5685 Problem A
  6. sdut2623--The number of steps(概率dp第一弹,求期望)
  7. 解决android自带textview右侧文字不能对齐的问题
  8. VMware SphereESXi上传系统镜像
  9. Javascript高级程序设计读书笔记(第二章)
  10. unison实时双向数据同步