Hello All,
The FtpPutFile from wininet.dll is returning false everytime i try to upload some thing to FTP.
Below is the code snippet that i am using:
[DllImport("wininet.dll", SetLastError = true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool FtpPutFile(IntPtr hConnect, string lpszLocalFile,
string lpszNewRemoteFile, int dwFlags, IntPtr dwContext);
private Int32 INTERNET_OPTION_CONNECTED_STATE = 50;
private Int32 INTERNET_STATE_CONNECTED = 1;
private uint INTERNET_FLAG_RELOAD = 0x80000000;
private const int InternetFlagTransferBinary = 0x00000002;
struct INTERNET_CONNECTED_INFO
{
public Int32 dwConnectedState;
public Int32 dwFlags;
}
private string _ipaddress = string.Empty;
private string _username= string.Empty;
private string _password = string.Empty;
{
try
{
IntPtr hSession = InternetOpen("FTP", 1, string.Empty, string.Empty, 4000000);
IntPtr hConnect = InternetConnect(hSession, _ipaddress, 21, _username, _password, 1, 2, IntPtr.Zero);
bool status = FtpPutFile(hConnect,localfile,remoteFile,(int)INTERNET_FLAG_RELOAD,IntPtr.Zero);
InternetCloseHandle(hConnect);
InternetCloseHandle(hSession);
ErrorLog.WriteLogMsg("UploadFile(): Status: " + result);
if (status == false)
{
var error = Marshal.GetLastWin32Error();
throw new Exception(
string.Format("UploadFile failed: {0}", error));
}
return status;
}
catch (Exception ex)
{
ErrorLog.WriteErrorLog(ex);
return false;
}
}
Please let me know why i am getting "status" as false everytime. Is there any syntax problem or something else.
Thank you.