How to create windows server using C# to transfer files via FTP? I have a folder that every x minutes are feeded by xml files that my ERP system generates... I need to send to my extern server via FTP. I think running a windows service every 30 minutes and loop through all files on this folder and sending via FTP is enough. Can you help me? Any exemples? Using .net vs2k8 is my development envronment. Thank you very much
Asked
Active
Viewed 2,679 times
-1
-
3Your question is broad. What part are you having problems with? What have you got so far? This is something you could do easily with a scheduled batch file. – D'Arcy Rittich Sep 18 '12 at 17:57
-
If you only need help with the Ftp client code - http://stackoverflow.com/questions/1264326/file-transfer-using-ftp – Orn Kristjansson Sep 18 '12 at 18:00
2 Answers
0
You can try with this code
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://....");
request.Method = WebRequestMethods.Ftp.UploadFile;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential ("anonymous","...");
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader("testfile.txt");
byte [] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
response.Close();

Aghilas Yakoub
- 28,516
- 5
- 46
- 51
0
How to transfer the file is in the answer from Aghilas
I would create it as a Service so you can have it auto start
Rather than poll the directory you can just use
Maybe log any failed uploads

Antony Scott
- 21,690
- 12
- 62
- 94

paparazzo
- 44,497
- 23
- 105
- 176