here's a simple winapi wrapper that i've used
using System;
using System.Runtime.InteropServ
public class Ftp
{
#region CloseConnection
[DllImport("WININET.DLL", EntryPoint="InternetCloseH
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="InternetConnec
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="FtpCreateDirec
public static extern bool MakeDir(int hFtpSession, string Directory);
#endregion
#region FtpGetCurrentDirectoryA
[DllImport("WININET.DLL", EntryPoint="FtpGetCurrentD
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("WebClientFtpTran
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(FtpDirector
return ret;
}
Ftp.CloseConnection(ftpSsn
Main Topics
Browse All Topics





by: martinvPosted on 2004-11-29 at 11:13:23ID: 12699112
You could try http://www.rebex.net/ftp.n et and http://www.rebex.net/ftp.n et/samples .aspx.
I really like it, but you could not trust me :-), as I'm biased (I work for Rebex)...