FTP in Compact framework

  • Thread starter Thread starter Ofer B.
  • Start date Start date
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);
}
}
 
Hi all
Can I use FTP in the compact framework

Thanks Ofer

There are FTP components available for CF already. You don't have
to write your own unless you just want to. There is an FTP component included
in IP*Works! .Net CF Edition (you can find this at www.nsoftware.com/download/).
There is also an SSL enabled FTPS component available as
well.

Regards,
Lance R.
/n software
http://www.nsoftware.com/

-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top