2
目前我的应用程序的FTP上传部分如下所示。我需要做的是,上传target_file_tmp_name
文件,上传完成后将其移动(或重命名)为target_file_name
。无法弄清楚如何等待上传完成,然后重命名远程文件。在C#中使用FTP移动文件
有什么建议吗?
var result_file_name = root_dir + "\\" + file_name + ".eps";
System.Uri target_file_name = new Uri(ftp_path + "/" + file_name + ".eps");
System.Uri target_file_tmp_name = new Uri(ftp_path + "/" + file_name + ".tmp");
await WhenFileCreated(result_file_name);
if (File.Exists(result_file_name))
{
SetProgressText("Uploading to server...");
WebClient wc_uploader = new WebClient();
wc_uploader.Credentials = new NetworkCredential("user", "pass");
wc_uploader.UploadFileCompleted += FinishProcess;
wc_uploader.UploadFileAsync(target_file_tmp_name, "STOR", result_file_name);
}
好像你上传到直接希望的目标的名字吗?这有什么问题? – Fildor
@Fildor在给它起名字之前需要等待完成上传。另一方面cronjob工作和processiing未完成的上传也 – demonoid
啊,我明白了。你有没有尝试过一些关于FTP重命名的Stackoverflow问题的答案?像这样:http://stackoverflow.com/a/13026258/982149我想你必须先在'FinishProcess'事件处理程序中启动重命名,并且首先使用'target_file_tmp_name'作为STORE命令。 – Fildor