如何在FTP服务器中移动文件

问题描述 投票:2回答:1

我想将文件从FTP服务器移动到同一服务器中的另一个目录。我认为我必须使用的方法是Rename。好吧,我不能继续,因为我不知道如何。在put或get操作中有数据流但不在这里,这是我的问题

$ftprequest = [System.Net.FtpWebRequest]::create($Source)
$ftprequest.Credentials = New-Object System.Net.NetworkCredential($user,$pass)  
$ftprequest.Method = [System.Net.WebRequestMethods+Ftp]::Rename   
$ftpresponse = $ftprequest.GetResponse()
powershell ftp file-rename ftpwebrequest
1个回答
1
投票

使用FtpWebRequest.RenameTo property指定目标名称(路径):

$ftprequest.Method = [System.Net.WebRequestMethods+Ftp]::Rename   
$ftprequest.RenameTo = "/another/directory/filename.ext"
$ftprequest.GetResponse().Dispose()

请注意,您不需要GetResponse()方法的结果。

© www.soinside.com 2019 - 2024. All rights reserved.