使用powershell在ftp中创建一个新文件

时间:2015-01-06 06:58:39

标签: c# powershell ftp powershell-v3.0 ftp-client

我需要将文件上传到ftp,以下是我正在尝试的内容

# Config
$Username = "XXX"
$Password = "XXX"
$LocalFile = "E:\shell\File1.xml"
$RemoteFile = "ftp://XXX/Folder1/File1.xml"

# Create a FTPWebRequest 
$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 
# Loop through the download 
do { 
    $ReadLength = $ResponseStream.Read($ReadBuffer,0,1024) 
    $LocalFileFile.Write($ReadBuffer,0,$ReadLength) 
} 
while ($ReadLength -ne 0)

现在我收到一条错误说明

Exception calling "GetResponse" with "0" argument(s): "The remote server returned an error: (550) File unavailable (e.g., file not found, no access).

默认情况下我没有在ftp中创建任何文件。我想要脚本从本地文件内容创建一个新文件。

我做错了什么?

0 个答案:

没有答案