Hi All,
I'm building a service that regularly backs up a set of files via FTP, and am having some problems. I have a class (from:
http://dotnetperls.com/recursively-find-files) that recursively builds a listing of the source directory and subdirectories. Then I upload using an FtpWebRequest. The upload works fine for the individual files in the root directory, but dies with a "550 - File Unavailable" error when it gets to the subdirectories.
I'm writing the path out to file as a means of debugging and it looks to be ok to me, so I'm not sure what's going on. My Ftp code follows. Thanks in advance.
List<string> dirs = FileHelper.GetFilesRecursive(@"C:<source
directory>"); foreach (string p in dirs) {
StringBuilder builder
= new StringBuilder(p);
//remove leading directory info and reverse
slashes builder.Remove(0, 38); builder.Replace('\\',
'/');
FtpWebRequest request =
(FtpWebRequest)WebRequest.Create("ftp://<server IP>" +
builder); //StringBuilder builder2 = new StringBuilder("ftp://<server
IP>" + builder); //writer.WriteLine(builder2); request.Timeout =
10000; request.ReadWriteTimeout = 10000; request.UseBinary =
true; request.KeepAlive = true; request.Method =
WebRequestMethods.Ftp.UploadFile;
FileInfo uploadFile = new
FileInfo(p); request.ContentLength = uploadFile.Length; int buffLength =
2048; byte[] buff = new byte[buffLength]; int
contLength;
FileStream fStream = uploadFile.OpenRead();
Stream
requestWriter = request.GetRequestStream(); contLength = fStream.Read(buff,
0, buffLength);
while (contLength != 0) { requestWriter.Write(buff,
0, buffLength); contLength = fStream.Read(buff, 0,
buffLength); }
requestWriter.Close(); fStream.Close(); }
|