簡體   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