File copy from Remote machine probelm

File copy from Remote machine probelm

am 05.01.2008 12:05:56 von Bhavesh

Hi everybody,

I have problem in copying file from DatabaseServer to WebServer.Both
machines are on LAN.

Let me explain in details what i am doing & wht i want to achieve...

I am using sqlserver 2000 & asp.net 2005 for my project..

I have written one stored procedure which creates one Text file on
database server.. & i want to copy that file in virtual path of my
project on webserver..

I am using following statement to copy a file..

strTextFileName = "E:\DestinationReportText\"


File.Copy(ConfigurationManager.AppSettings("ExportToTextFold erForCopy")
& ViewState("ReportName") & ".txt", strTextFileName)

and in web.config following is the value




When i debug code on webserver then everything works well, but when i
run this code from IIS on same machine then it gives following
Error ..
/*********************************************************** **
Server Error in '/www' Application.
------------------------------------------------------------ --------------------

Logon failure: unknown user name or bad password.

Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.IO.IOException: Logon failure: unknown user
name or bad password.
***********************************************************/

and to solve this I have given Full permission for "Report_Text"
folder to admin user, to anonymous user, & tried other lots of
stuffs,, but cound not make it to work...

is any one have idea on this ?

Re: File copy from Remote machine probelm

am 06.01.2008 14:28:55 von Toze

you must give permission on the remote machine... to the user that the iis
is running (IUSR)

Exemple:
IIS HOST - MACHINE NAME - IISHOST
FILE HOST - MACHINE NAME - FILEHOST
You must giver permission in the folder on the FILEHOST to
IISHOST\IUSR_IISHOST


"Bhavesh" wrote in message
news:0d0fc609-fe2a-4e0f-97c1-c9318796b986@d4g2000prg.googleg roups.com...
> Hi everybody,
>
> I have problem in copying file from DatabaseServer to WebServer.Both
> machines are on LAN.
>
> Let me explain in details what i am doing & wht i want to achieve...
>
> I am using sqlserver 2000 & asp.net 2005 for my project..
>
> I have written one stored procedure which creates one Text file on
> database server.. & i want to copy that file in virtual path of my
> project on webserver..
>
> I am using following statement to copy a file..
>
> strTextFileName = "E:\DestinationReportText\"
>
>
> File.Copy(ConfigurationManager.AppSettings("ExportToTextFold erForCopy")
> & ViewState("ReportName") & ".txt", strTextFileName)
>
> and in web.config following is the value
>
>
>

>
> When i debug code on webserver then everything works well, but when i
> run this code from IIS on same machine then it gives following
> Error ..
> /*********************************************************** **
> Server Error in '/www' Application.
> ------------------------------------------------------------ --------------------
>
> Logon failure: unknown user name or bad password.
>
> Description: An unhandled exception occurred during the execution of
> the current web request. Please review the stack trace for more
> information about the error and where it originated in the code.
>
> Exception Details: System.IO.IOException: Logon failure: unknown user
> name or bad password.
> ***********************************************************/
>
> and to solve this I have given Full permission for "Report_Text"
> folder to admin user, to anonymous user, & tried other lots of
> stuffs,, but cound not make it to work...
>
> is any one have idea on this ?

Re: File copy from Remote machine probelm

am 08.01.2008 16:02:35 von George Ter-Saakov

Here is the code you can use to access shared file with given
username/password


//used in calling WNetAddConnection2
[StructLayout(LayoutKind.Sequential)]
public struct NETRESOURCE
{
public int dwScope;
public int dwType;
public int dwDisplayType;
public int dwUsage;
[MarshalAs(UnmanagedType.LPStr)]
public string lpLocalName;
[MarshalAs(UnmanagedType.LPStr)]
public string lpRemoteName;
[MarshalAs(UnmanagedType.LPStr)]
public string lpComment;
[MarshalAs(UnmanagedType.LPStr)]
public string lpProvider;
}
//WIN32API - WNetAddConnection2
[DllImport("mpr.dll",
CharSet = System.Runtime.InteropServices.CharSet.Auto)]
private static extern int WNetAddConnection2A(
[MarshalAs(UnmanagedType.LPArray)] NETRESOURCE[] lpNetResource,
[MarshalAs(UnmanagedType.LPStr)] string lpPassword,
[MarshalAs(UnmanagedType.LPStr)] string lpUserName,
int dwFlags);
[DllImport("mpr.dll",
CharSet = System.Runtime.InteropServices.CharSet.Auto)]
private static extern int WNetCancelConnection2A(
[MarshalAs(UnmanagedType.LPStr)] string lpName,
int dwFlags, int fForce);

private byte[] GetFSMSFile(string sFile)
{
NETRESOURCE[] nr = new NETRESOURCE[1];
nr[0].lpRemoteName = "\\SHAREDSERVER\FOLDER";
nr[0].lpLocalName = ""; //mLocalName;
nr[0].dwType = 1; //disk
nr[0].dwDisplayType = 0;
nr[0].dwScope = 0;
nr[0].dwUsage = 0;
nr[0].lpComment = "";
nr[0].lpProvider = "";
int iErr = WNetAddConnection2A(nr,UserPassword, ShareUser, 0);
if (iErr > 0)
throw new Exception("Can not connect to shared folder");
FileStream st = null;
try
{
st = new FileStream("\\SHAREDSERVER\FOLDER\myfile.txt",
FileMode.Open);
int iLen = (int)st.Length;
byte []b = new byte[iLen];
st.Read(b, 0, iLen);
return b;
}
finally
{
if( st != null )
st.Close();
WNetCancelConnection2A(_sFSMSShare, 0, -1);
}
}


"Bhavesh" wrote in message
news:0d0fc609-fe2a-4e0f-97c1-c9318796b986@d4g2000prg.googleg roups.com...
> Hi everybody,
>
> I have problem in copying file from DatabaseServer to WebServer.Both
> machines are on LAN.
>
> Let me explain in details what i am doing & wht i want to achieve...
>
> I am using sqlserver 2000 & asp.net 2005 for my project..
>
> I have written one stored procedure which creates one Text file on
> database server.. & i want to copy that file in virtual path of my
> project on webserver..
>
> I am using following statement to copy a file..
>
> strTextFileName = "E:\DestinationReportText\"
>
>
> File.Copy(ConfigurationManager.AppSettings("ExportToTextFold erForCopy")
> & ViewState("ReportName") & ".txt", strTextFileName)
>
> and in web.config following is the value
>
>
>

>
> When i debug code on webserver then everything works well, but when i
> run this code from IIS on same machine then it gives following
> Error ..
> /*********************************************************** **
> Server Error in '/www' Application.
> ------------------------------------------------------------ --------------------
>
> Logon failure: unknown user name or bad password.
>
> Description: An unhandled exception occurred during the execution of
> the current web request. Please review the stack trace for more
> information about the error and where it originated in the code.
>
> Exception Details: System.IO.IOException: Logon failure: unknown user
> name or bad password.
> ***********************************************************/
>
> and to solve this I have given Full permission for "Report_Text"
> folder to admin user, to anonymous user, & tried other lots of
> stuffs,, but cound not make it to work...
>
> is any one have idea on this ?