将文件移动到另一个 FTP 位置时,您必须将 RenameTo 与新的 FTP 位置一起使用.
When moving a file to another FTP location you must use RenameTo with the new FTP location.
在本例中,如何使用 RenameTo 移动到新的 FTP 位置?
In this example how do you use RenameTo to move to the new FTP location?
FtpWebRequest ftpRequest = null;
FtpWebResponse ftpResponse = null;
try
{
ftpRequest = (FtpWebRequest)WebRequest.Create("ftp://mysite.com/folder1/fileName.ext");
ftpRequest.Credentials = new NetworkCredential("user", "pass");
ftpRequest.UseBinary = true;
ftpRequest.UsePassive = true;
ftpRequest.KeepAlive = true;
ftpRequest.Method = WebRequestMethods.Ftp.Rename;
ftpRequest.RenameTo = "ftp://mysite.com/folder2/fileName.ext";
ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
ftpResponse.Close();
ftpRequest = null;
}
catch (Exception ex) { Label1.Text = (ex.ToString()); }
为 .RenameTo 属性设置目标路径,而不是 URL:
Set a target path to .RenameTo property, not URL:
ftpRequest.RenameTo = "/folder2/fileName.ext";
根据 FtpWebRequest 的 MSDN 文档.RenameTo 属性:
As per MSDN documentation for FtpWebRequest.RenameTo property:
获取或设置要重命名的文件的新名称.
Gets or sets the new name of a file being renamed.
比较 WebRequest.Create 方法:
Compare to WebRequest.Create method:
为指定的 URI 方案初始化一个新的 WebRequest 实例.
Initializes a new WebRequest instance for the specified URI scheme.
RenameTo 中的 URL 将是多余的,因为您不能使用它来重命名".文件到另一台服务器.
The URL would be redundant in RenameTo, as you cannot use it to "rename" the file to another server.
这篇关于使用 FtpWebRequest 重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
ASP.NET Core 使用 Azure Active Directory 进行身份验证并ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 进行身
ASP.NET Core 2.0 Web API Azure Ad v2 令牌授权不起作用ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授权不起作用)
ASP Core Azure Active Directory 登录使用角色ASP Core Azure Active Directory Login use roles(ASP Core Azure Active Directory 登录使用角色)
如何获取守护进程或服务器到 C# ASP.NET Web API 的How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何获取守护进程或服务器到 C# ASP.N
.Net Core 2.0 - 获取 AAD 访问令牌以与 Microsoft Graph.Net Core 2.0 - Get AAD access token to use with Microsoft Graph(.Net Core 2.0 - 获取 AAD 访问令牌以与 Microsoft Graph 一起使用)
异步调用时 Azure KeyVault Active Directory AcquireTokenAAzure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(异步调用时 Azure KeyVault Active Directory AcquireTokenAsync 超