【发布时间】:2013-12-27 12:15:38
【问题描述】:
尝试查找文件并将其上传到 ftp 服务器,我想我一切都正确,但它没有上传任何内容
string filepath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
DirectoryInfo d = new DirectoryInfo(filepath);
List<String> allDatfiles = Directory
.GetFiles(filepath, "data.dat", SearchOption.AllDirectories).ToList();
foreach (string file in allDatfiles)
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.test.com/Holder");
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("User", "Pass");
request.UseBinary = true;
request.UsePassive = true;
byte[] data = File.ReadAllBytes(file); // Think the problem is with file
request.ContentLength = data.Length;
Stream stream = request.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();
}
还尝试使用 @"C... 将文件位置作为字符串放入 我没有收到任何错误,上传后没有文件显示
【问题讨论】:
-
您是否尝试过在调试器中运行代码并在运行时检查变量内容?我们从这里看不到它们,也不知道文件是否在您要查找的位置。您将不得不自己调试它以查看失败的原因。
-
是的,文件在那个位置,甚至尝试使用具有特定名称的文本文件,但没有任何效果
-
调试器不会抛出任何错误
-
我没有说“抛出错误”。请阅读我写的内容。我们无法单步执行代码来查看发生了什么问题,因为我们无法看到它在运行时在做什么。只有您可以这样做,因为只有您有权访问它。
标签: c# file-upload ftp