使用Powershell在FTP上重命名文件 - (553)不允许使用文件名

时间:2017-06-26 13:02:56

标签: powershell ftp

我有一个脚本可以在FTP服务器上传文件。我想通过重命名文件并在文件名末尾添加"_complete"来标记我的FTP上传过程是否成功。

我确实在寻找答案,我已按照this question中的步骤重命名文件,但我在最后一行收到错误。

以下是脚本的90%(除了我初始化值,用户,通行证,ftp地址等的部分。)

# Destination filename
$destination_filename = $ftp_addr+$backup_source_app_data.BaseName+"_"+$script_start_time.hour+"-"+$script_start_time.minute+"-"+$script_start_time.second

# Initialize connection to FTP
$ftp = [System.Net.FtpWebRequest]::Create($destination_filename+".zip")
$ftp = [System.Net.FtpWebRequest]$ftp
$ftp.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
$ftp.Credentials = new-object System.Net.NetworkCredential($user, $pass)

$ftp.Timeout = -1              #infinite timeout
$ftp.ReadWriteTimeout = -1     #infinite timeout

$ftp.UseBinary = $true
$ftp.UsePassive = $true

sz a -mx=3 $backup_target_app_data $backup_source_app_data.FullName

$requestStream = $ftp.GetRequestStream()
$fileStream = [System.IO.File]::OpenRead($backup_target_app_data)
$chunk = New-Object byte[] $bufSize

while( $bytesRead = $fileStream.Read($chunk,0,$bufsize) )
{
    $requestStream.write($chunk, 0, $bytesRead)
    $requestStream.Flush()
}

$FileStream.Close()
$requestStream.Close()

$ftp = [System.Net.FtpWebRequest]::Create($destination_filename+".zip")
$ftp.KeepAlive = $true
$ftp.UsePassive = $true
$ftp.Method = [System.Net.WebRequestMethods+Ftp]::Rename
$ftp.Credentials = new-object System.Net.NetworkCredential($user, $pass)
$ftp.RenameTo = $destination_filename + "_complete" + ".zip"
$ftp.UseBinary = $true
$response = [System.Net.FtpWebResponse] $ftp.GetResponse()

我得到的错误是:

  

异常调用" GetResponse"用" 0"参数:"遥控器   服务器返回错误:(553)不允许文件名。"在   C:\ Users \ rgheorghiu \ Desktop \ Untitled2.ps1:75 char:61   + $ response = [System.Net.FtpWebResponse] $ ftp.GetResponse<<<< ()       + CategoryInfo:NotSpecified:(:) [],MethodInvocationException       + FullyQualifiedErrorId:DotNetMethodException

我不知道我能做些什么来克服这个问题。任何帮助表示赞赏。

0 个答案:

没有答案