【问题标题】:How to move files in the FTP server如何在 FTP 服务器中移动文件
【发布时间】:2019-07-19 09:30:11
【问题描述】:

我想将文件从 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】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-18
    • 1970-01-01
    • 2017-08-26
    • 2016-01-29
    • 2012-01-09
    相关资源
    最近更新 更多