# 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时候,切记文件名是区分大小写滴!

[Powershell] FTP Download File的更多相关文章

  1. FTP Download File By Some Order List

    @Echo Off REM -- Define File Filter, i.e. files with extension .RBSet FindStrArgs=/E /C:".asp&q ...

  2. FTP(File Transfer Protocol)是什么?

    文件传输协议 FTP(File Transfer Protocol),是文件传输协议的简称.用于Internet上的控制文件的双向传输.同时,它也是一个应用程序(Application).用户可以通过 ...

  3. Csharp:WebClient and WebRequest use http download file

    //Csharp:WebClient and WebRequest use http download file //20140318 塗聚文收錄 string filePath = "20 ...

  4. C# show FTP Download/Upload progress

    https://stackoverflow.com/questions/4591059/download-file-from-ftp-with-progress-totalbytestoreceive ...

  5. python ftp download with progressbar

    i am a new one to learn Python. Try to download by FTP. search basic code from baidu. no one tells h ...

  6. PowerShell: 如何解决File **.ps1 cannot be loaded because the execution of scripts is disabled on this sy

    PowerShell 默认不允许执行*.ps1脚本文件.运行ps1文件会得到下面的错误: File C:\Temp\Test.ps1 cannot be loaded because the exec ...

  7. SharePoint 2007 Full Text Searching PowerShell and CS file content with SharePoint Search

    1. Ensure your site or shared folder in one Content Source. 2. Add file types. 3. The second step in ...

  8. Download file using libcurl in C/C++

    http://stackoverflow.com/questions/1636333/download-file-using-libcurl-in-c-c #include <stdio.h&g ...

  9. httpClient download file(爬虫)

    package com.opensource.httpclient.bfs; import java.io.DataOutputStream; import java.io.File; import ...

随机推荐

  1. leetcode: sortlist之四种方法

    原题链接:https://oj.leetcode.com/problems/sort-list/ 题目:空间复杂度为常数,时间复杂度为O(nlogn)的排序链表实现 方法一:第一想法是模拟数组的快速排 ...

  2. bzoj1681[Usaco2005 Mar]Checking an Alibi 不在场的证明

    Description A crime has been comitted: a load of grain has been taken from the barn by one of FJ's c ...

  3. hdu5023--A Corrupt Mayor's Performance Art

    来源:2014 ACM/ICPC Asia Regional Guangzhou Online 题意:长度为n的一个线段,1-30为颜色代号.初始状态每个单位长度颜色都为2,然后有q次操作,P操作把区 ...

  4. <php>统计整个文件夹的大小

    //用来统计一个目录下大小 function dirsize($file) { $size = 0; $dir = opendir($file); while($filename = readdir( ...

  5. poj 2112 Optimal Milking (二分图匹配的多重匹配)

    Description FJ has moved his K ( <= K <= ) milking machines <= C <= ) cows. A ..K; the c ...

  6. python3-day3(函数-参数)

    1.参数 函数的核心是参数传值,其次是返回值,熟练这两这个技术即可灵活使用函数. 1>普通参数 def  show(name): print(name) show('tom') 2>默认参 ...

  7. Qt使用QGraphicsView实现滑动窗体效果

    QGraphicsView用来显示一个滚动视图区的QGraphicsScene内容.QGraphicsScene提供了QGraphicsItem的容器功能.通常与QGraphicsView一起使用来描 ...

  8. JavaScript 之 call apply bind

    关键字 this 绑定的方法 this的动态切换,固然为JavaScript创造了巨大的灵活性,但也使得编程变得困难和模糊.有时,需要把this固定下来,避免出现意想不到的情况.JavaScript提 ...

  9. WebDAV被启用(转)

    WebDAV (Web-based Distributed Authoring and Versioning) 一种基于 HTTP 1.1协议的通信协议.它扩展了HTTP 1.1,在GET.POST. ...

  10. SqlDbHelper备份,做项目时方便应用(目前不太全,把自己项目中的逐渐转移过来)

    ****************************************** 这是官网新闻左侧类别那部分用到的 **************************************** ...