• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 691
  • Last Modified:

FTp componenet for .Net c#

Anybody knows a good ftp component in c#. I ahve search google and i found lots of them but I am just curiouse to see other programmers experince with them. Any good suggestion?
0
prokni
Asked:
prokni
2 Solutions
 
martinvCommented:
You could try http://www.rebex.net/ftp.net and http://www.rebex.net/ftp.net/samples.aspx.

I really like it, but you could not trust me :-), as I'm biased (I work for Rebex)...
0
 
msdixonCommented:
here's a simple winapi wrapper that i've used

using System;
using System.Runtime.InteropServices;
public class Ftp
{
   #region CloseConnection
   [DllImport("WININET.DLL", EntryPoint="InternetCloseHandle")]
   public static extern int CloseConnection(int HINet);
   #endregion

   #region Open
   [DllImport("WININET.DLL", EntryPoint="InternetOpenA")]
   public static extern int Open(string sAgent, int lAccessType, string sProxyName, string sProxyBypass, int lFlags);
   #endregion
       
   #region Connect
   [DllImport("WININET.DLL", EntryPoint="InternetConnectA")]
   public static extern int Connect(int hInternetSession, string sServerName, int nServerPort,
      string sUsername, string sPassword, int lService, int lFlags, int lContext);
   #endregion
   #region PutFile
   [DllImport("WININET.DLL", EntryPoint="FtpPutFileA")]
   public static extern bool PutFile(int hFtpSession, string lpszLocalFile, string lpszRemoteFile,
      int dwFlags, int dwContext);
   #endregion
   #region MakeDir
   [DllImport("WININET.DLL", EntryPoint="FtpCreateDirectoryA")]
   public static extern bool MakeDir(int hFtpSession, string Directory);
   #endregion
   #region FtpGetCurrentDirectoryA
   [DllImport("WININET.DLL", EntryPoint="FtpGetCurrentDirectoryA")]
   public static extern string GetCurrentDirectory(int FtpSession, string Directory);
   #endregion
   #region GetFile
   [DllImport("WININET.DLL", EntryPoint="FtpGetFileA")]
   public static extern bool GetFile(int hFtpSession, string lpszRemoteFile, string lpszNewFile,
      bool fFailIfExists, int dwFlagsAndAttributes, int dwFlags, int dwContext);
   #endregion
}




************* usage ******************
         int inetSsn = Ftp.Open("WebClientFtpTransfer", 0, null, null, 0);
         if (inetSsn == 0)
         {
            lblResults.Text += "<span class=\"Error\">Could not connect to the FTP Server</span><br>";
            return;
         }
         int ftpSsn = Ftp.Connect(inetSsn, ftpServer, 21, ftpUser, ftpPw, 1, 0, 0);

         // check to see if Internet session was successful
         if (ftpSsn == 0)
         {
            lblResults.Text += "<span class=\"Error\">Could not connect to FTP Server: " + ftpServer + "</span><br>";
            return;
         }

// ftpsession is the variable from the connect method
// local is the fully qualified path for the local file
// remote is the relative path and file name on the server
                  if (!Ftp.PutFile(FtpSession, local, remote, 0, 0))
                  {
                     ret.Append("<span class=\"error\">Error copying file: " + remote.Replace(FtpDirectory, "") + "</span><br>");
                     return ret;
                  }

         Ftp.CloseConnection(ftpSsn);
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now