กำลังพยายามค้นหาไฟล์และอัปโหลดไปยังเซิร์ฟเวอร์ 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... ฉันไม่ได้รับข้อผิดพลาด และไม่มีไฟล์ปรากฏขึ้นหลังจากการอัปโหลด