473,473 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

File copy from Remote machine probelm

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("Export ToTextFolderForCopy")
& ViewState("ReportName") & ".txt", strTextFileName)

and in web.config following is the value
<appSettings>
<add key="ExportToTextFolderForCopy" value="\\DBServerCompName
\Report_Text\" />
</appSettings>

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 ?
Jan 5 '08 #1
2 5469
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" <bh*********@gmail.comwrote in message
news:0d**********************************@d4g2000p rg.googlegroups.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("Export ToTextFolderForCopy")
& ViewState("ReportName") & ".txt", strTextFileName)

and in web.config following is the value
<appSettings>
<add key="ExportToTextFolderForCopy" value="\\DBServerCompName
\Report_Text\" />
</appSettings>

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 ?

Jan 6 '08 #2

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" <bh*********@gmail.comwrote in message
news:0d**********************************@d4g2000p rg.googlegroups.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("Export ToTextFolderForCopy")
& ViewState("ReportName") & ".txt", strTextFileName)

and in web.config following is the value
<appSettings>
<add key="ExportToTextFolderForCopy" value="\\DBServerCompName
\Report_Text\" />
</appSettings>

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 ?

Jan 8 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jon Maz | last post by:
Hi All, To allow myself to make development changes directly on a remote server *without* having to compile on my local dev machine and then upload the dll's to remote, I have created a...
2
by: Paul | last post by:
Dear All, I want to use web form to upload my file and copy the file to another machine. I can upload the file, but when I copy the file(file.CopyTo(".....", true)) to another machine(map...
1
by: POnfri | last post by:
Hi, I have a problem in a peace of code were i'm doing a file copy using File.Copy. The Source is local and the target is a remote machine. Example: File.Copy(C:\temp\hi.txt,...
2
by: Stu | last post by:
Using IIs 6.0 on a Server 2003 box, and using ASP.NET I'm trying to do the following code snippit... Dim NewName As String = "\\network_share_path\edit_me.ppt" Dim PubName As String =...
2
by: Steve Franks | last post by:
The Copy Web tool provided with VS.NET 2005 is very convenient. However every once in a while it seems to think the files on the remote server have changed, which they have not. Then when I use...
1
by: Mark | last post by:
The new file based web server that comes with Visual Studio 2005 allows you to develop and debug an ASP.NET on a remote computer rather than having to rely on IIS. Assuming you've got decent LAN...
1
by: Coaster | last post by:
If I am calling File.CopyTo make a backup copy of a remote file on a remote machine where the source and destination locations are both on the remote machine would it be faster to call the function...
1
shrek123
by: shrek123 | last post by:
I want to kill some process on remote machine which is on some other domain. I am using Win32::OLE GetObject to do that. But I am getting following error Error1: When my remote machine is on...
5
by: =?Utf-8?B?QWRyaWFuTW9ycmlz?= | last post by:
Hello! I'm trying to copy a file from another computer on the network that I do not have permission with my current logon details to access. If I open the folder using the Windows file manager...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.