[英]FTP - Uploading a file in a diffrent name
I have a form which has radiobuttons, each of them is giving a file name in a string, and what I want to do is to have that string as a name for any file that a user uploads.我有一个带有单选按钮的表单,它们每个都在字符串中给出一个文件名,我想要做的是将该字符串作为用户上传的任何文件的名称。
It'll be great if you could explain to me how to rename, because I already got it the code to upload or just help me modify this function, I would probably have to add to the parameters "string type" tho:如果您能向我解释如何重命名,那就太好了,因为我已经得到了要上传的代码,或者只是帮我修改这个 function,我可能不得不添加到参数“字符串类型”寿:
public void uploadFTP(string filename, string type, string password, ProgressBar progressbar)
{
WebClient client = new WebClient();
client.Credentials = new System.Net.NetworkCredential("username", password);
try
{
client.UploadFileAsync(new Uri(@"ftp://ftpaddress.com" + "/" + new FileInfo(filename).Name), "STOR", filename);
}
catch(System.InvalidCastException)
{
// Handled it
}
catch (System.ArgumentException)
{
// Handled it
}
client.UploadProgressChanged += (s, e) =>
{
progressbar.Value = e.ProgressPercentage;
};
client.UploadFileCompleted += (s, e) =>
{
MessageBox.Show("Upload complete", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
};
}
If it's important: The files are RTF (RichTextBox).如果它很重要:文件是 RTF (RichTextBox)。
Thanks!谢谢!
Just upload to different URL then.只需上传到不同的 URL 即可。 Replace
new FileInfo(filename).Name
in your code with the name you actually want.将代码中的
new FileInfo(filename).Name
替换为您实际想要的名称。 Also, I think not using string manipulation is better.另外,我认为不使用字符串操作会更好。 And the STOR command is the default.
STOR 命令是默认的。
client.UploadFileAsync(new Uri(new Uri("ftp://ftpaddress.com"), newName)), filename);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.