首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Windows设备to...anywhere传输文件

从Windows设备to...anywhere传输文件
EN

Stack Overflow用户
提问于 2010-07-22 20:59:05
回答 2查看 2K关注 0票数 0

我似乎找不到解决这个问题的办法。我正在努力使Windows 6上的Compact应用程序能够将其本地文件系统上的文件移动到另一个系统。

以下是我所知道的解决方案:

  • FTP的问题在于,大多数API的使用成本都很高。
  • HTTP -据我所能找到的,我不能在IIS7中使用匿名PUT,这是系统正在运行的web服务器。(解决这一问题的一个极端方法是使用不同的web服务器来放置文件,并让其他系统将其传输到IIS系统)。
  • Windows共享--我需要对这些共享进行身份验证,而且我还没有看到通过windows mobile通过该身份验证的方法。

最后的办法是要求这些设备能够传输这些文件,但我真的很想让这些文件能够无线传输。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-08-11 19:19:34

最后,我只是通过PHP脚本向web服务器传递信息。

上面所提供的选择对我的情况没有效果。

这是它的要点。我在里面有一些代码,里面有进度条,以及各种检查和处理程序,它们与简单地发送文件无关,但我相信您可以从中挑出。我已经从C#和PHP中删除了我的身份验证代码,但是如果有必要的话,使用自己的代码应该不会太困难。

在C#中:

代码语言:javascript
复制
/*
 * Here's the short+sweet about how I'm doing this
 * 1) Copy the file from mobile device to web server by querying PHP script with paramaters for each line
 * 2) PHP script checks 1) If we got the whole data file 2) If this is a duplicate data file
 * 3) If it is a duplicate, or we didn't get the whole thing, it goes away. The mobile 
 *    device will hang on to it's data file in the first case (if it's duplicate it deletes it)
 *    to be tried again later
 * 4) The server will then process the data files using a scheduled task/cron job at an appropriate time
 */
private void process_attempts()
{   

    Uri CheckUrl = new Uri("http://path/to/php/script?action=check");
    WebRequest checkReq = WebRequest.Create(CheckUrl);
    try
    {
        WebResponse CheckResp = checkReq.GetResponse();
        CheckResp.Close();
    }
    catch
    {
        MessageBox.Show("Error! Connection not available. Please make sure you are online.");
        this.Invoke(new Close(closeme));
    }
    StreamReader dataReader = File.OpenText(datafile);
    String line = null;
    line = dataReader.ReadLine();
    while (line != null)
    {
        Uri Url = new Uri("http://path/to/php/script?action=process&line=" + line);
        WebRequest WebReq = WebRequest.Create(Url);
        try
        {
          WebResponse Resp = WebReq.GetResponse();
          Resp.Close();
        }
        catch
        {
            MessageBox.Show("Error! Connection not available. Please make sure you are online.");
            this.Invoke(new Close(closeme));
            return;
        }
        try
        {
            process_bar.Invoke(new SetInt(SetBarValue), new object[] { processed });
        }
        catch { }
        process_num.Invoke(new SetString(SetNumValue), new object[] { processed + "/" + attempts });
        processed++;
        line = dataReader.ReadLine();
    }
    dataReader.Close();
    Uri Url2 = new Uri("http://path/to/php/script?action=finalize&lines=" + attempts);
    Boolean finalized = false;
    WebRequest WebReq2 = WebRequest.Create(Url2);
    try
    {
        WebResponse Resp = WebReq2.GetResponse();
        Resp.Close();
        finalized = true;
    }
    catch
    {
        MessageBox.Show("Error! Connection not available. Please make sure you are online.");
        this.Invoke(new Close(closeme));
        finalized = false;
    }
    MessageBox.Show("Done!");
    this.Invoke(new Close(closeme));
}

在PHP中(为您的利益做了彻底的评论!):

代码语言:javascript
复制
<?php

//Get the GET'd values from the C#

//The current line being processed
$line = $_GET['line'];
//Which action we are doing
$action = $_GET['action'];
//# of lines in the source file
$totalLines = $_GET['lines'];

//If we are processing the line, open the data file, and append this new line and a newline.
if($action == "process"){
    $dataFile = "tempdata/SOME_KIND_OF_UNIQUE_FILENAME.dat";
    //open the file
    $fh = fopen($dataFile, 'a');
    //Write the line, and a newline to the file
    fwrite($fh, $line."\r\n");
    //Close the file
    fclose($fh);
    //Exit the script
    exit();
}

//If we are done processing the original file from the C# application, make sure the number of lines in the new file matches that in the 
//file we are transferring. An expansion of this could be to compare some kind of hash function value of both files...
if($action == "finalize"){
    $dataFile = "tempdata/SOME_KIND_OF_UNIQUE_FILENAME.dat";
    //Count the number of lines in the new file
    $lines = count(file($dataFile));
    //If the new file and the old file have the same number of lines...
    if($lines == $totalLines){
        //File has the matching number of lines, good enough for me over TCP.
            //We should move or rename this file.
    }else{
        //File does NOT have the same number of lines as the source file.
    }
    exit();
}

if($action == "check"){
    //If a file with this unique file name already exists, delete it.
    $dataFile = "tempdata/SOME_KIND_OF_UNIQUE_FILENAME.dat";
    if(file_exists($dataFile)){
        unlink($dataFile);
    }
}
?>
票数 1
EN

Stack Overflow用户

发布于 2010-07-22 21:49:12

  • FTP:定义“太贵”。您是指性能、字节开销或美元成本吗?这是一个有源代码的免费的
  • IIS7当然支持托管web服务自定义IHttpHandlers。您可以很容易地使用这两种方式进行数据上传。
  • Windows共享只需要您访问P/调用WNet API来映射共享,但它并不是非常复杂。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3313417

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档