使用 PowerShell 重命名 FTP 上的文件 [英] Rename file on FTP with PowerShell
本文介绍了使用 PowerShell 重命名 FTP 上的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法重命名 FTP 目录中的文件?我正在将实时图像从计算机流式传输到 FTP,但问题是当它将图像上传到 FTP 时,它会立即替换文件.我想先上传带有临时名称的图像,然后重命名为 live.jpg.就像缓存文件上传一样.
Is there a way to rename the file in a FTP directory? I'm streaming live images from computer to FTP, but problem is that when it uploads the image to FTP it making instant replacement of a file. I want to firstly upload image with temporary name and then make a rename to live.jpg. It's gonna be like cached file uploading.
while($true)
{
$i++
$File = "c:live emp.jpg"
$ftp = "ftp://username:password@example.com/camera/temp.jpg"
$webclient = New-Object System.Net.WebClient
$uri = New-Object System.Uri($ftp)
$webclient.UploadFile($uri, $File)
}
如何在脚本中正确使用它?
How can I use this in script properly ?
Rename-Item ..camera emp.jpg live.jpg
谢谢!
推荐答案
试试这个:
$ftp = [System.Net.FtpWebRequest]::Create("ftp://username:password@example.com/camera/temp.jpg")
$ftp.KeepAlive = $true
$ftp.UsePassive = $true
$ftp.Method = "Rename"
$ftp.RenameTo = "camera/temp1.jpg"
$ftp.UseBinary = $true
$response = [System.Net.FtpWebResponse] $ftp.GetResponse()
这篇关于使用 PowerShell 重命名 FTP 上的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文