I can get this one it to work on a local ftp server but not on a outside one
http://www.allapi.net/classlib/class.php?id=23
i think you can import the win32 calls but i can't get that to work either.
GetlastError after InternetConnect always returns 12029 (
ERROR_INTERNET_CANNOT_CONNECT) even though i am connect to the internet.
public class ftp
{
public const UInt32 INTERNET_OPEN_TYPE_PRECONFIG = 0;
public const long INTERNET_OPEN_TYPE_DIRECT = 1;
public const long INTERNET_OPEN_TYPE_PROXY = 3;
public const long INTERNET_FLAG_RELOAD = 0x80000000;
public const long FTP_TRANSFER_TYPE_UNKNOWN = 0;
public const long FTP_TRANSFER_TYPE_ASCII = 1;
public const long FTP_TRANSFER_TYPE_BINARY = 2;
public const UInt16 INTERNET_DEFAULT_FTP_PORT = 21;
public const UInt32 INTERNET_FLAG_PASSIVE = 0x08000000;
public const UInt32 INTERNET_SERVICE_FTP = 1;
[ DllImport("wininet.dll", EntryPoint="InternetConnectW",
CharSet=CharSet.Unicode) ]
private static extern Int32 InternetConnectW(Int32 hInternet,
string ServerName, UInt16 ServerPort,
string sUserName, string sPassword, UInt32 nService,
UInt32 nFlags, UInt32 nContext);
[ DllImport("wininet.dll", EntryPoint="InternetOpenW",
CharSet=CharSet.Unicode) ]
public static extern Int32 InternetOpenW(string sAgent, UInt32
nAccessType, string sProxy,
string sProxyBypass, UInt32 nFlags);
[DllImport("coredll.dll", EntryPoint="FtpPutFileW")]
public static extern long FtpPutFile(
long hFtp,
string
lpszLocalFile,
string
lpszNewRemoteFile,
long dwFlags,
long dwContext);
[DllImport("coredll.dll", EntryPoint="InternetCloseHandle")]
public static extern long InternetCloseHandle(long hInet);
[DllImport("CoreDll.dll")]
private extern static Int32 GetLastError();
private Int32 lInternetHandle = 0;
private long lFtpHandle = 0;
public bool InitializeFTP()
{
lInternetHandle = InternetOpenW("FTPOpen",
INTERNET_OPEN_TYPE_PRECONFIG, "", "", 0);
if(lInternetHandle == 0)
MessageBox.Show("BAD");
else
MessageBox.Show("Good");
return (lInternetHandle > 0);
}
public bool ConnectToFTPServer(string strFTPServerName, string
strUsername, string strPassword)
{
lFtpHandle = InternetConnectW(lInternetHandle,
strFTPServerName,
INTERNET_DEFAULT_FTP_PORT, strUsername,
strPassword,
INTERNET_SERVICE_FTP,
INTERNET_FLAG_PASSIVE, 0);
long lError = GetLastError();
if(lFtpHandle == 0)
MessageBox.Show("BAD");
else
MessageBox.Show("Good");
return (lFtpHandle > 0);
}
public bool PutFileOnFtPServer(string strSourceFilename, string
strDestFilename, bool blnBinaryFile)
{
long lTranferredOK;
long lTransferType;
if(blnBinaryFile)
lTransferType = FTP_TRANSFER_TYPE_BINARY;
else
lTransferType = FTP_TRANSFER_TYPE_ASCII;
lTranferredOK = FtpPutFile(lFtpHandle, strSourceFilename,
strDestFilename,
lTransferType, 0);
return (lTranferredOK > 0);
}
public void CloseFTP()
{
InternetCloseHandle(lFtpHandle);
InternetCloseHandle(lInternetHandle);
}
}