繁体   English   中英

FTP - 上传不同名称的文件

[英]FTP - Uploading a file in a diffrent name

我有一个带有单选按钮的表单,它们每个都在字符串中给出一个文件名,我想要做的是将该字符串作为用户上传的任何文件的名称。

如果您能向我解释如何重命名,那就太好了,因为我已经得到了要上传的代码,或者只是帮我修改这个 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);
    };
}

如果它很重要:文件是 RTF (RichTextBox)。

谢谢!

只需上传到不同的 URL 即可。 将代码中的new FileInfo(filename).Name替换为您实际想要的名称。 另外,我认为不使用字符串操作会更好。 STOR 命令是默认的。

client.UploadFileAsync(new Uri(new Uri("ftp://ftpaddress.com"), newName)), filename);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM