Accessing Dahua Configuration using CSharp

misternote

n3wb
Joined
May 17, 2023
Messages
3
Reaction score
0
Location
England
Hello Community,

i'm currently working on an app which is able to configure read and configure several cams (similar to ispyconnect).

Everything works fine so far, but getting the ftp configuration from a dahua device is not possible.

I tried changing the struct several times, same as trying several configs.

Attached is one of a few code attempts which returns either "User parameter is illegal" or "there is no sufficient buffer".

Maybe someone was able to get it working before..



/ user parameter is illegal
public void GetFTPConfigFromDvr(...)
{

FTP_PROTO_CFG_EX? ftpConfig = new();
IntPtr pConfig = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DHDEV_FTP_PROTO_CFG)));
int bufSize = Marshal.SizeOf(typeof(DHDEV_FTP_PROTO_CFG));
object obj = ftpConfig;

bool ret = DHNetSDK.QueryDevState(_loginId, (int)EM_DEV_CFG_TYPE.FTP_PROTO_CFG_EX, ref obj, typeof(DHDEV_FTP_PROTO_CFG), 15000);
if (!ret)
log.Error($"Problem while getting FTP config {DHNetSDK.GetLastError()}");
}


public void GetFTPConfigFromDvr(...)
{
int nRetLen = 0;
IntPtr stuChn = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(FTP_PROTO_CFG_EX)));
Marshal.StructureToPtr(new FTP_PROTO_CFG_EX(), stuChn, false);
var success = DHNetOriginalSDK.CLIENT_QueryDevState(_loginId, 0x0050, stuChn, Marshal.SizeOf(typeof(FTP_PROTO_CFG_EX)), ref nRetLen, 3000);
}

My structure looks like that:



[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct DHDEV_FTP_PROTO_CFG
{
public uint dwSize;
public bool bEnable;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string szHostIp;
public ushort wHostPort;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string szDirName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public string szUserName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public string szPassword;
public int iFileLen;
public int iInterval;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16 * 7)]
public DH_FTP_UPLOAD_CFG[] struUploadCfg;
public byte protocol;
public byte NASVer;
public uint dwFunctionMask;
public byte bDataType;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 123)]
public byte[] reserved;
}


public struct FTP_PROTO_CFG_EX
{
public uint dwSize;
public uint dwEnableFTP;
public uint dwProtocol;
public uint dwAddress;
public ushort wPort;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public byte[] szUserName;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public byte[] szPassword;
public ushort wInterval;
public ushort wConnectTime;
public ushort wRetryTimes;
public ushort wPacketSize;
public uint dwMode;
public uint dwServerPathMode;
public ushort wServerCustomPort;
public ushort wClientCustomPort;
public byte bAnonymous;
}

Thank you .. :)
 
Top