2013-11-25 187 views
0

我已经编写了一个程序来与远程服务器同步文件。但我无法找到一种方法来通过服务器的用户名密码&。我已经提供了下面的代码。它在两个本地目录之间工作。我在这里使用了微软同步框架。但即使在搜索解决方案的天数之后,我也无法修改它以与远程服务器一起使用。有人可以让我知道在这里包括凭据的方式。在此先感谢与远程服务器同步文件

string RemoteserverPath = "https://xxx.xxx.xxx.xxx.com/login/login.jsp"; 
     string ClientPath = "E:/test"; 

     try 
     { 
      FileSyncOptions options = FileSyncOptions.ExplicitDetectChanges | 
        FileSyncOptions.RecycleDeletedFiles | FileSyncOptions.RecyclePreviousFileOnUpdates | FileSyncOptions.RecycleConflictLoserFiles; 

      FileSyncScopeFilter filter = new FileSyncScopeFilter(); 
      filter.FileNameExcludes.Add("*.lnk"); // Exclude all *.lnk files 

      DetectChangesOnFileSystemReplica(
       RemoteserverPath, filter, options); 
      DetectChangesOnFileSystemReplica(
       ClientPath, filter, options); 

      // Sync in both directions 
      SyncFileSystemReplicasOneWay(RemoteserverPath, ClientPath, null, options); 
      SyncFileSystemReplicasOneWay(ClientPath, RemoteserverPath, null, options); 
      MessageBox.Show("Done"); 
     } 
     catch (Exception e1) 
     { 
      MessageBox.Show("\nException from File Sync Provider:\n" + e1.ToString());     
     } 
+0

如果服务器支持,您可以尝试在URL字符串中指定凭据。 – AgentFire

+0

你真的想将文件发送到登录页面,还是我误解你的代码? –

+0

@AgentFire,你好我改变了我的编码如下。但它会抛出一个错误消息,称为“标识符预期”。 string replica1RootPath =“https://data-set1.xxx.xxx.xxxxx.com”,“xxx”,“xxxx”; –

回答

0

您不能使用Microsoft Sync Framework来同步这样的ftp(远程)文件。您必须使用代理服务器供应商(如WCF)与微软同步框架同步

+0

你可以提供如何创建代理提供程序或任何好链接的示例 –

+0

我是sory,但我没有任何例子。我认为这很难编码,所以我在没有Microsoft Sync Framework的情况下对其进行编码,我在数据库中编写了文件信息,然后在FTP上将它们与我的代码进行了同步。 – hubeybozkul