FTP FtpFindFile

  • Thread starter Thread starter Xavier PACOTTE
  • Start date Start date
X

Xavier PACOTTE

Hello,

I work under window ce.net 5.0(C#) with the Wininet.dll librairy for the
FTP.
I want have the files list of a FTP directory.
I tried the "FtpFindFirstFile" function but it blocks my application.
Have you got some informations on this problem?
Have you got an example to list a directory?

Best regards
 
Post the code which is causing you trouble and we can probably suggest
something.

Peter
 
My code:

[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool FtpFindFirstFile(
int hConnect,string lpszSearchFile,WIN32_FIND_DATA lpFindFileData,UInt32
dwFlags,int dwContext);

StructLayout(LayoutKind.Sequential)]
public struct WIN32_FIND_DATA
{
public uint fileAttributes;
public FILETIME creationTime;
public FILETIME lastAccessTime;
public FILETIME lastWriteTime;
public uint fileSizeHigh;
public uint fileSizeLow;
public uint reserved0;
public uint reserved1;
public char[] fileName;
public char[] alternateFileName;
}


WIN32_FIND_DATA pData;


FtpFindFirstFile(FTPHandle, "*.*", pData, INTERNET_FLAG_NO_CACHE_WRITE, 0);
 
I'm sure those char arrays cannot be right.

-Chris

Xavier PACOTTE said:
My code:

[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool FtpFindFirstFile(
int hConnect,string lpszSearchFile,WIN32_FIND_DATA lpFindFileData,UInt32
dwFlags,int dwContext);

StructLayout(LayoutKind.Sequential)]
public struct WIN32_FIND_DATA
{
public uint fileAttributes;
public FILETIME creationTime;
public FILETIME lastAccessTime;
public FILETIME lastWriteTime;
public uint fileSizeHigh;
public uint fileSizeLow;
public uint reserved0;
public uint reserved1;
public char[] fileName;
public char[] alternateFileName;
}


WIN32_FIND_DATA pData;


FtpFindFirstFile(FTPHandle, "*.*", pData, INTERNET_FLAG_NO_CACHE_WRITE,
0);

Peter Foot said:
Post the code which is causing you trouble and we can probably suggest
something.

Peter
 
Also as a struct you should be passing the find data by reference e.g.
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool FtpFindFirstFile(int hConnect,string
lpszSearchFile, ref WIN32_FIND_DATA lpFindFileData, UInt32 dwFlags,int
dwContext);

And your find data struct should look like this (for .NETCF v2.0)
StructLayout(LayoutKind.Sequential)]
public struct WIN32_FIND_DATA
{
public uint fileAttributes;
public FILETIME creationTime;
public FILETIME lastAccessTime;
public FILETIME lastWriteTime;
public uint fileSizeHigh;
public uint fileSizeLow;
public uint reserved0;
public uint reserved1;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=260)]
public string fileName;
}

Peter

--
Peter Foot
Device Application Development MVP
www.peterfoot.net | www.inthehand.com

I'm sure those char arrays cannot be right.

-Chris

Xavier PACOTTE said:
My code:

[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool FtpFindFirstFile(
int hConnect,string lpszSearchFile,WIN32_FIND_DATA lpFindFileData,UInt32
dwFlags,int dwContext);

StructLayout(LayoutKind.Sequential)]
public struct WIN32_FIND_DATA
{
public uint fileAttributes;
public FILETIME creationTime;
public FILETIME lastAccessTime;
public FILETIME lastWriteTime;
public uint fileSizeHigh;
public uint fileSizeLow;
public uint reserved0;
public uint reserved1;
public char[] fileName;
public char[] alternateFileName;
}


WIN32_FIND_DATA pData;


FtpFindFirstFile(FTPHandle, "*.*", pData, INTERNET_FLAG_NO_CACHE_WRITE,
0);

Peter Foot said:
Post the code which is causing you trouble and we can probably suggest
something.

Peter

--
Peter Foot
Device Application Development MVP
www.peterfoot.net | www.inthehand.com

Hello,

I work under window ce.net 5.0(C#) with the Wininet.dll librairy for
the FTP.
I want have the files list of a FTP directory.
I tried the "FtpFindFirstFile" function but it blocks my application.
Have you got some informations on this problem?
Have you got an example to list a directory?

Best regards
 
Thank you for informations. In fact the good definitions is (it missed the 2
first characters
in the filename) :
[StructLayout(LayoutKind.Sequential)]
public struct WIN32_FIND_DATA
{
public int fileAttributes;
public FILETIME creationTime;
public FILETIME lastAccessTime;
public FILETIME lastWriteTime;
public int fileSizeHigh;
public int fileSizeLow;
public short reserved0;
public short reserved1;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string fileName;
}

Peter Foot said:
Also as a struct you should be passing the find data by reference e.g.
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool FtpFindFirstFile(int hConnect,string
lpszSearchFile, ref WIN32_FIND_DATA lpFindFileData, UInt32 dwFlags,int
dwContext);

And your find data struct should look like this (for .NETCF v2.0)
StructLayout(LayoutKind.Sequential)]
public struct WIN32_FIND_DATA
{
public uint fileAttributes;
public FILETIME creationTime;
public FILETIME lastAccessTime;
public FILETIME lastWriteTime;
public uint fileSizeHigh;
public uint fileSizeLow;
public uint reserved0;
public uint reserved1;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=260)]
public string fileName;
}

Peter

--
Peter Foot
Device Application Development MVP
www.peterfoot.net | www.inthehand.com

I'm sure those char arrays cannot be right.

-Chris

Xavier PACOTTE said:
My code:

[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool FtpFindFirstFile(
int hConnect,string lpszSearchFile,WIN32_FIND_DATA lpFindFileData,UInt32
dwFlags,int dwContext);

StructLayout(LayoutKind.Sequential)]
public struct WIN32_FIND_DATA
{
public uint fileAttributes;
public FILETIME creationTime;
public FILETIME lastAccessTime;
public FILETIME lastWriteTime;
public uint fileSizeHigh;
public uint fileSizeLow;
public uint reserved0;
public uint reserved1;
public char[] fileName;
public char[] alternateFileName;
}


WIN32_FIND_DATA pData;


FtpFindFirstFile(FTPHandle, "*.*", pData, INTERNET_FLAG_NO_CACHE_WRITE,
0);

"Peter Foot [MVP]" <[email protected]> a écrit dans le
message de news: (e-mail address removed)...
Post the code which is causing you trouble and we can probably suggest
something.

Peter

--
Peter Foot
Device Application Development MVP
www.peterfoot.net | www.inthehand.com

Hello,

I work under window ce.net 5.0(C#) with the Wininet.dll librairy for
the FTP.
I want have the files list of a FTP directory.
I tried the "FtpFindFirstFile" function but it blocks my application.
Have you got some informations on this problem?
Have you got an example to list a directory?

Best regards
 
Back
Top