Main Area and Open Discussion > General Software Discussion
functional C# class/component to upload to my DC space via explicit FTP over TLS
kyrathaba:
I have no problem doing this via Filezilla, but I need to figure out how to upload a file to my little corner of DC programmatically, from within my C# applications. I've tried various things, from FTP classes I've both found and rolled myself, and using HttpWebRequest. I also read about the winhttp.dll library, which some people say works whereas the internal C# stuff is not always robust (however, I have no experience with that library's functions).
The reason I need to be able to do this programmatically is that I've coded a game. That game records the highscore, and updates that value whenever a player beats the previous high score. I want the program to be able to upload the highscore.dat file (which contains not only the highscore, but also the name of the player who scored it) to a specific directory under http://kyrathaba.dcmembers.com
Does anyone have any working C# code that they've used successfully to upload a file to their DC webspace? I know that DC uses explict FTP over TLS. Perhaps the methods I've attempted aren't sophisticated enough to negotiate that. At any rate, it'd be a real boon (not just to my current project, but also to future ones) if I could find a class or component that allows me this functionality.
I have used the code show here before successfully, on a non FTPES site, but can't get it to work here.
Renegade:
Have you looked at the Indy Project? I think there are C# bindings for it.
EDIT:
Yes -- here -- http://www.indyproject.org/SocketsCLR/index.EN.aspx
kyrathaba:
Thanks for the possible help. Looks like the project hasn't been updated since Feb. 2008, and that was has been done is mostly focused on SMTP/POP. The only FTP related stuff I could find, so far, was:
--- Code: C# ---using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace Indy.Sockets.Web { class FTP { }}
I'll keep looking through the download and documentation, though, just to be thorough.
kyrathaba:
I tried the following code in a console program, and received this error message: The remote server returned an error: (530) Not logged in.
--- End quote ---
--- Code: C# ---static void Main(string[] args) { // Get the object used to communicate with the server. FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://kyrathaba.dcmembers.com/testbed/test.txt"); request.Method = WebRequestMethods.Ftp.UploadFile; request.Credentials = new NetworkCredential("kyrathaba", "substitutedForActualPasswordInThisForumPost"); // Copy the contents of the file to the request stream. StreamReader sourceStream = new StreamReader("test.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(); Console.WriteLine("Press a key to end program..."); Console.ReadKey(); }
hamradio:
Only concern I got is how are you going to keep people from using a .net disassembler to see the password?
Navigation
[0] Message Index
[#] Next page
Go to full version