Changing FTP from binary to ascii in PowerShell script using WebClient(使用 WebClient 在 PowerShell 脚本中将 FTP 从二进制更改为 ascii)
问题描述
简单的 PowerShell 脚本.它下载一个文件(二进制)没有问题.我需要它在ASCII中.
Simple PowerShell script. It downloads a file (in binary) with no issues. I need it in ascii.
$File = "c: empftpfile.txt"
$ftp = "ftp://myusername:mypass@12.345.6.78/'report'";
$webclient = New-Object -TypeName System.Net.WebClient;
$uri = New-Object -TypeName System.Uri -ArgumentList $ftp;
$webclient.DownloadFile($uri, $File);
推荐答案
WebClient不支持ascii/text FTP模式.
The WebClient does not support ascii/text FTP mode.
使用 FtpWebRequest 而是设置 .UseBinary代码> 为假.
Use FtpWebRequest instead and set .UseBinary to false.
$File = "c: empftpfile.txt"
$ftp = "ftp://myusername:mypass@12.345.6.78/'report'";
$ftprequest = [System.Net.FtpWebRequest]::Create($ftp)
$ftprequest.Method = [System.Net.WebRequestMethods+Ftp]::DownloadFile
$ftprequest.UseBinary = $false
$ftpresponse = $ftprequest.GetResponse()
$responsestream = $ftpresponse.GetResponseStream()
$targetfile = New-Object IO.FileStream($File, [IO.FileMode]::Create)
$responsestream.CopyTo($targetfile)
$targetfile.close()
参考:在 PowerShell 中自动化安全 FTP 的最佳方法是什么?
请注意,WebClient 在内部使用 FtpWebRequest,但不公开其 .UseBinary 属性.
Note that the WebClient uses the FtpWebRequest internally, but does not expose its .UseBinary property.
这篇关于使用 WebClient 在 PowerShell 脚本中将 FTP 从二进制更改为 ascii的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 WebClient 在 PowerShell 脚本中将 FTP 从二进制更
基础教程推荐
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
