[Powershell] FTP Download File
# 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的更多相关文章
- FTP Download File By Some Order List
@Echo Off REM -- Define File Filter, i.e. files with extension .RBSet FindStrArgs=/E /C:".asp&q ...
- FTP(File Transfer Protocol)是什么?
文件传输协议 FTP(File Transfer Protocol),是文件传输协议的简称.用于Internet上的控制文件的双向传输.同时,它也是一个应用程序(Application).用户可以通过 ...
- Csharp:WebClient and WebRequest use http download file
//Csharp:WebClient and WebRequest use http download file //20140318 塗聚文收錄 string filePath = "20 ...
- C# show FTP Download/Upload progress
https://stackoverflow.com/questions/4591059/download-file-from-ftp-with-progress-totalbytestoreceive ...
- 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 ...
- 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 ...
- 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 ...
- Download file using libcurl in C/C++
http://stackoverflow.com/questions/1636333/download-file-using-libcurl-in-c-c #include <stdio.h&g ...
- httpClient download file(爬虫)
package com.opensource.httpclient.bfs; import java.io.DataOutputStream; import java.io.File; import ...
随机推荐
- WPF:如何实现单实例的应用程序(Single Instance)
原文:WPF:如何实现单实例的应用程序(Single Instance) 好吧,这是我将WPF与Windows Forms进行比较的系列文章的第四篇,讨论一下如何实现单实例(single instan ...
- 函数call相关[ASM]
前言: __cdecl:C/C++函数默认调用约定,参数依次从右向左传递,并压入堆栈,最后由调用函数清空堆栈,这种方式适用于传递参数个数可变的被调用函数,只有被调用函数才知道它传递了多少个参数给被 ...
- NSIS操作系统环境变量
手头有个项目需要修改PATH变量 需要!include "EnvVarUpdate.nsh" 以下是NSIS脚本代码 ; Script generated by the HM NI ...
- Spring中Bean的命名问题及ref和idref之间的区别
一直在用Spring,其实对其了解甚少,刚去了解了一下Spring中Bean的命名问题以及ref和idref之间的区别,略作记录,以备后查. Spring中Bean的命名 1.每个Bean可以有一个i ...
- 3D打印论坛
3D打印论坛:http://www.3done.cn http://www.03dp.com www.qjxxw.net/ http://www.3ddayin.net http://oa.zol.c ...
- Linux企业级项目实践之网络爬虫(14)——使用正则表达式抽取HTML正文和URL
正则表达式,又称正规表示法.常规表示法(英语:Regular Expression,在代码中常简写为regex.regexp或RE),计算机科学的一个概念.正则表达式使用单个字符串来描述.匹配一系列符 ...
- Go语言的构建方法总结
趁着近期要换工作的空闲时间,看了一下Go语言,与C++相比,Go语言的确在不少地方轻便了不少,例如:增加了内置的字符串类型.多个返回值.支持协程.简单的构建方法等等.使得在生产效率方面有了不少的提高. ...
- 上传图片代码(chuantouxiang.php+touxiangchuli.php)
<body> <form action="touxiangchuli.php" method="post" enctype="mul ...
- SegmentFault 巨献 1024 程序猿游戏「红岸的呼唤」第三天任务攻略
第三关也不是一般的难呐,那么继续写一下解题过程(第四关会是什么样呢?). 高速传送门:http://segmentfault.com/game/3 在用我想到的方法(booth算法.矩阵变换.各种CP ...
- cookie 和 session
会话(Session)跟踪是Web程序中常用的技术,用来跟踪用户的整个会话.常用的会话跟踪技术是Cookie与Session.Cookie通过在客户端记录信息确定用户身份,Session通过在服务器端 ...