我有一个c# webapp,我需要允许用户将整个文件夹及其内容上传到服务器。我的代码仅在本地测试时才有效,因为它正在搜索本地目录的所有内容并上传。
当我将应用程序部署到服务器时,我不确定如何保持这个工作。有人知道允许您一次上传整个文件夹的 Web 界面示例吗?
private void uploadWebsite(string dirPath, string uploadPath, string imagesPath)
{
string[] files = Directory.GetFiles(dirPath, "*.*");
string[] subDirs = Directory.GetDirectories(dirPath);
foreach (string file in files)
{
ftpClient.upload(uploadPath + "/" + Path.GetFileName(file), file);
if (file.Contains(".jpg") || file.Contains(".png") || file.Contains(".gif"))
ftpClient.upload(uploadPath + "/images/" + Path.GetFileName(file), file);
}
foreach (string subDir in subDirs)
{
ftpClient.createDirectory(uploadPath + "/" + Path.GetFileName(subDir));
uploadWebsite(subDir, uploadPath + "/" + Path.GetFileName(subDir), null);
}
}