1

サーバーから別のサーバーに多くのフォルダーをコピーする必要があります。サーバーは異なるドメインにあります。tcpまたはftpを使用する必要がありますか?サーバーにアクセスするためのログイン資格情報を持っています。次のようなものを使用することは可能ですか?

string sourceFile = @"ServerIP\C:\Users\Public\public\test.txt";
string destinationFile = @"Localhost\C:\Users\Public\private\test.txt";

// To move a file or folder to a new location:
System.IO.File.Copy(sourceFile, destinationFile);
4

2 に答える 2

4

以下のコードスニペットを使用して、それを行うというアイデアをつかむことができます。LogonUserを使用して、ドメインアカウントだけでなく、ローカルグループになりすますことができます。

Directory / Folder内のすべてのコンテンツ(ファイル)をコピーするには、明らかに、名前空間Directory内のクラスを使用してすべてのファイル情報を取得できます。System.IO

コード:

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Security.Permissions;

public class Form1
{
    [DllImport("advapi32.DLL", SetLastError = true)]
    public static extern int LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
    private void Button1_Click(System.Object sender, System.EventArgs e)
    {
        IntPtr admin_token = default(IntPtr);
        WindowsIdentity wid_current = WindowsIdentity.GetCurrent();
        WindowsIdentity wid_admin = null;
        WindowsImpersonationContext wic = null;
        try {
            MessageBox.Show("Copying file...");
            if (LogonUser("Local Admin name", "Local computer name", "pwd", 9, 0, ref admin_token) != 0) {
                wid_admin = new WindowsIdentity(admin_token);
                wic = wid_admin.Impersonate();
                System.IO.File.Copy("C:\\right.bmp", "\\\\157.60.113.28\\testnew\\right.bmp", true);
                MessageBox.Show("Copy succeeded");
            } else {
                MessageBox.Show("Copy Failed");
            }
        } catch (System.Exception se) {
            int ret = Marshal.GetLastWin32Error();
            MessageBox.Show(ret.ToString(), "Error code: " + ret.ToString());
            MessageBox.Show(se.Message);
        } finally {
            if (wic != null) {
                wic.Undo();
            }
        }
    }
}

参照:ローカルアカウントになりすます

于 2012-10-30T05:15:27.833 に答える
-1

のようなものを使用することは可能ですか?

あなたはそれを自分で見つけてはいけませんか?

にとって

サーバーから別のサーバーに多くのフォルダーをコピーする必要があります

System.Net.FtpWebRequestFTPを使用するには、とを使用する必要がありますSystem.Net.WebRequestMethods.Ftp

見る:

http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx

http://msdn.microsoft.com/en-us/library/system.net.webrequestmethods.ftp.aspx

また、グーグルでの簡単な検索はこれを行うための多くの良い方法を与えました、https://www.google.co.in/search?q = copy + files + from + one + server + to + another + using + asp.net

これらのいずれかを試してみてください。実装時に問題が発生した場合は、ここに来て「その」質問をしてください。逆ではありません。

于 2012-10-30T05:12:05.680 に答える