关于图片上传保存到另一台服务器问题

wisdonlz 2010-09-03 05:40:11
由于公司OA图纸无纸化功能是把文件扫描成图片,然后上传到服务,然后全公司的都从OA上查看图纸。由之前只是一个部门的图纸,比较小。但是现在公司准备全公司都实现无纸,OA服务硬盘容量不够了,但公司又不肯加大OA服务器硬盘容量,原因:此服务器的硬盘很贵。所以现在考虑是图片到保存别的服务。
问题:这样的功能能不能实现呢? 能的话,该怎么做呢?

ps:您只允许发表200分内的帖子。 没办法了,只能最大200分了。
...全文
618 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
chen8410 2010-09-04
  • 打赏
  • 举报
回复
不然就偷懒一下,用框架吧
wisdonlz 2010-09-04
  • 打赏
  • 举报
回复
大家帮帮忙
wwfgu00ing 2010-09-04
  • 打赏
  • 举报
回复
关注当中。。。
孟子E章 2010-09-04
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 wisdonlz 的回复:]
按wosizy 的那个文章所说,建虚拟目录 映射到\\192.169.0.115\upload,显示拒绝访问 ,但是右击 找开它可以访问。在浏览器输入192.169.0.115\upload也可以访问。为什么,在IIS显示拒绝访问呢??
[/Quote]

我给的代码都是全丢了改什么啊?

为什么,在IIS显示拒绝访问??
那是因为iis是匿名访问的啊。

照着上面的做,就可以了,我测试过的。

不要遗漏任何一个环节!!
bychgh 2010-09-04
  • 打赏
  • 举报
回复
学习了~~~~~~~~~~~~~~~~~~~~~
周公 2010-09-04
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 wisdonlz 的回复:]
有沒有人做過的,請幫幫
[/Quote]
1、可以在要保存的图片的服务器上做个简单的ASP.NET网站,仅仅包括上传网页就可以了,在这里可以实现保存代码,在OA服务器上调用就OK了;
2、如果在同一个局域网类,可以磁盘映射来解决。如以下命令:net use Z: \\192.168.21.51\file
这样就想操作本地磁盘一样保存文件了,需要解决有文件服务器上的用户名和密码;
3、在图片服务商部署WCF或者Web Service接口来接收文件数据,类似于方法一;
4、在图片服务器上安装FTP服务器软件,使用FtpClient来保存。

方法1和方法2相对简单。
wisdonlz 2010-09-04
  • 打赏
  • 举报
回复
有沒有人做過的,請幫幫
wisdonlz 2010-09-03
  • 打赏
  • 举报
回复
按wosizy 的那个文章所说,建虚拟目录 映射到\\192.169.0.115\upload,显示拒绝访问 ,但是右击 找开它可以访问。在浏览器输入192.169.0.115\upload也可以访问。为什么,在IIS显示拒绝访问呢??
q107770540 2010-09-03
  • 打赏
  • 举报
回复
关 注
wisdonlz 2010-09-03
  • 打赏
  • 举报
回复
各位老大,看一下我的代碼怎么改啊。
wuyq11 2010-09-03
  • 打赏
  • 举报
回复
<system.web>
<identity impersonate="true" userName="User01" password="对应User01的密码" />
</system.web>
然后A服务器和B服务器上都创建该用户
public class NetFileSave
{
[DllImport("advapi32.dll", SetLastError = true)]
private static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private unsafe static extern int FormatMessage(int dwFlags, ref IntPtr lpSource, int dwMessageId, int dwLanguageId, ref String lpBuffer, int nSize, IntPtr* arguments);

[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool CloseHandle(IntPtr handle);

[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public extern static bool DuplicateToken(IntPtr existingTokenHandle, int SECURITY_IMPERSONATION_LEVEL, ref IntPtr duplicateTokenHandle);

// logon types
const int LOGON32_LOGON_INTERACTIVE = 2;
const int LOGON32_LOGON_NETWORK = 3;
const int LOGON32_LOGON_NEW_CREDENTIALS = 9;

// logon providers
const int LOGON32_PROVIDER_DEFAULT = 0;
const int LOGON32_PROVIDER_WINNT50 = 3;
const int LOGON32_PROVIDER_WINNT40 = 2;
const int LOGON32_PROVIDER_WINNT35 = 1;
[STAThread]
public static bool FileSave(string strServer,string strAccount,string strPassword,string strFileFromPath,string strFileToPath)
{
IntPtr token = IntPtr.Zero;
IntPtr dupToken = IntPtr.Zero;

bool isSuccess = LogonUser(strAccount, strServer, strPassword, LOGON32_LOGON_NEW_CREDENTIALS, LOGON32_PROVIDER_DEFAULT, ref token);
if (!isSuccess)
{
RaiseLastError();
return false;
}

isSuccess = DuplicateToken(token, 2, ref dupToken);
if (!isSuccess)
{
RaiseLastError();
}

WindowsIdentity newIdentity = new WindowsIdentity(dupToken);
WindowsImpersonationContext impersonatedUser = newIdentity.Impersonate();

try
{
FileInfo srcFile = new FileInfo(strFileFromPath);
srcFile.MoveTo(strFileToPath);
}
catch
{
return false;
}

impersonatedUser.Undo();

isSuccess = CloseHandle(token);
if (!isSuccess)
{
RaiseLastError();
return false;
}

return true;
}

public unsafe static string GetErrorMessage(int errorCode)
{
int FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100;
int FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200;
int FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000;

int messageSize = 255;
string lpMsgBuf = "";
int dwFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;

IntPtr ptrlpSource = IntPtr.Zero;
IntPtr ptrArguments = IntPtr.Zero;

int retVal = FormatMessage(dwFlags, ref ptrlpSource, errorCode, 0, ref lpMsgBuf, messageSize, &ptrArguments);
if (retVal == 0)
{
throw new ApplicationException(
string.Format("Failed to format message for error code '{0}'.", errorCode));
}

return lpMsgBuf;
}

private static void RaiseLastError()
{
int errorCode = Marshal.GetLastWin32Error();
string errorMessage = GetErrorMessage(errorCode);

throw new ApplicationException(errorMessage);
}

}
wisdonlz 2010-09-03
  • 打赏
  • 举报
回复
按孟子所說,已配好用戶,但代碼不知道怎么改


string physicalFolder = "192.168.0.115\\data (F)\\ImgFiles\\";//data (F) 為另一臺服務器F盤
if (!Directory.Exists(physicalFolder))
{
Directory.CreateDirectory(physicalFolder);
}
FileStream fs = new FileStream(physicalFolder + img.FileName, FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(img.Data);
bw.Close();

wosizy 2010-09-03
  • 打赏
  • 举报
回复
可以用File.Copy复制到远程机器
但是你得先连接远程机器
可以用net use



如何把文件上传到另外一台服务器
http://www.cnblogs.com/Jwin/archive/2008/10/28/1320970.html
孟子E章 2010-09-03
  • 打赏
  • 举报
回复
将文件上传到网络共享服务器的方法

http://dotnet.aspx.cc/file/Upload-Files-TO-UNC-Share-Using-ASP.NET.aspx

1,在文件服务器上,创建一个本地帐户,比如登录名:upload,密码:upload,注意在创建的时候选择“密码永不过期”,去掉勾选“用户下次登录时须更改密码”的选项;
2,在要共享的文件夹上点右键,选择“属性”-“安全”,增加upload帐户可以写入的权限;
3,在要共享的文件夹上点右键,选择“共享”,共享此文件夹,并在“权限”按钮点击后添加帐户upload可修改;
4,在另外一台 Web 服务器上,创建登录名和密码与上面完全相同的本地帐户。
5,在web.config里,启用模拟:
web.config里添加的代码
<identity impersonate="true" userName="upload" password="upload" />

6,在网站文件夹和Temporary ASP.NET Files文件夹上设置帐户upload读写权限
7,在ASP.NET的上传文件里写:
C# 代码
protected void Button1_Click(object sender, EventArgs e)
{
string fileName = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.SaveAs(@"\\192.168.3.1\free\" + fileName);
}

8,显示上传的文件:
在IIS里创建虚拟目录,指向“另一台计算机上的共享”,“连接为”输入上面创建的帐户名和密码。即可以http://www.mengxianhui.com/upload/hello.jpg进行访问。

注意:在VS里面直接运行可能会报告
Could not load file or assembly 'WebApplication1' or one of its dependencies. 拒绝访问。
这是因为你模拟的帐户没有权限导致的,你可以发布到IIS看效果。

下面是一段使用程序进行模拟的方法,出自 http://2leggedspider.wordpress.com/2007/05/28/upload-files-to-unc-share-using-asp-net/ :
C# 代码

using System.Security.Principal;
using System.Runtime.InteropServices;

namespace FileUploadUNCShare
{
public partial class _Default : System.Web.UI.Page
{

public const int LOGON32_LOGON_INTERACTIVE = 2;
public const int LOGON32_PROVIDER_DEFAULT = 0;

WindowsImpersonationContext impersonationContext;

[DllImport("advapi32.dll")]
public static extern int LogonUserA(String lpszUserName,
String lpszDomain,
String lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int DuplicateToken(IntPtr hToken,
int impersonationLevel,
ref IntPtr hNewToken);

[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool RevertToSelf();

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern bool CloseHandle(IntPtr handle);

private bool ImpersonateUser(String userName, String domain, String password)
{
WindowsIdentity tempWindowsIdentity;
IntPtr token = IntPtr.Zero;
IntPtr tokenDuplicate = IntPtr.Zero;

if (RevertToSelf())
{
if (LogonUserA(userName, domain, password, LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT, ref token) != 0)
{
if (DuplicateToken(token, 2, ref tokenDuplicate) != 0)
{
tempWindowsIdentity = new WindowsIdentity(tokenDuplicate);
impersonationContext = tempWindowsIdentity.Impersonate();
if (impersonationContext != null)
{
CloseHandle(token);
CloseHandle(tokenDuplicate);
return true;
}
}
}
}
if (token != IntPtr.Zero)
CloseHandle(token);
if (tokenDuplicate != IntPtr.Zero)
CloseHandle(tokenDuplicate);
return false;
}

private void UndoImpersonation()
{
impersonationContext.Undo();
}

protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
if (ImpersonateUser("upload", "", "upload"))
{

if ((FileUpload1.PostedFile != null) && (FileUpload1.PostedFile.ContentLength > 0))
{
string fileName = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
string folderPath = @"\\MyUNCShare\MyFolder\";

string locationToSave = folderPath + "\\" + fileName;
try
{
FileUpload1.PostedFile.SaveAs(locationToSave);
Response.Write("The file has been uploaded.");
}
catch (Exception ex)
{
Response.Write("Error: " + ex.Message);
}
}
else
{
Response.Write("Please select a file to upload.");
}

UndoImpersonation();
}
else
{
Response.Write("Failed");
}

}
}
}
阿非 2010-09-03
  • 打赏
  • 举报
回复
FtpWebRequest

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧