使用PowerShell在FTP上重命名文件 [英] Rename file on FTP with PowerShell

查看:150
本文介绍了使用PowerShell在FTP上重命名文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在FTP目录中重命名文件?
我将实时图像从计算机传输到FTP,但问题是当它将图像上传到ftp时,它会立即替换文件。我想先用TEMP名称上传图片,然后重命名为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 TEMP name and then make a rename to live.jpg. It's gonna be like Cached file uploading.

while($true)
{
    $i++
$File = "c:\live\temp.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)
}

如何正确使用脚本?

Rename-Item ..\camera\temp.jpg live.jpg

Thanx!

推荐答案

试试这个:

Try this:

$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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆