开发者

FTP - Uploading a file in a diffrent name

I have a form which开发者_JAVA百科 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:

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).

Thanks!


Just upload to different URL then. Replace new FileInfo(filename).Name in your code with the name you actually want. Also, I think not using string manipulation is better. And the STOR command is the default.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜