我如何在服务器上更新文本文件 [英] How i can update text file on my server

查看:103
本文介绍了我如何在服务器上更新文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI
我正在寻求帮助,我有一个正在制作有关温度的日志文件的软件,并且无法使用该软件上载该文件,因此,我唯一的选择是必须制作一个读取该日志文件并获取最后一个条目并更新文件的软件服务器.

我只需要帮助

1)从计算机上的文件中读取文件
2)如何通过FTP连接到Web服务器.
3)更新服务器上的文件.

请指向我一些网站,休息,我会尽我所能.
我是编程新手.

我发现了这个 http://ftplib.codeplex.com/ [

HI
i am looking fr some help i have a software which is making log file about Temperature and i cannot upload the file using that software so the only option i have to make a software which read that log file and take last entry and update the file on the server.

i just need help for

1) Read the file from file which is on computer
2) how to connect to web server by FTP.
3) update the file on the server.

Please point me to some web sites rest i will do my self.
i am new to programming.

i found this http://ftplib.codeplex.com/[^] for ftp need help in read/update file for every 5 mints.

i am trying this i just need help to setup the right paths it is giving me error "Unable to connect to the remote server"


 static void Main(string[] args)
{
    StreamReader streamReader = new StreamReader("C:\\wamp\\www\\FTCPC\\logfile.txt");
    ArrayList lines = new ArrayList();

    string line;

    while ((line = streamReader.ReadLine()) != null)
    {
        lines.Add(line);
    }
    streamReader.Close();

    if (lines.Count > 0)
    {
        Console.Write(lines[lines.Count - 1].ToString());

    }

    // Get the object used to communicate with the server.
    FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/test.htm");
    request.Method = WebRequestMethods.Ftp.UploadFile;

    // This example assumes the FTP site uses anonymous logon.
    request.Credentials = new NetworkCredential("username", "password", "server ftp info");

    // Copy the contents of the file to the request stream.
    StreamReader sourceStream = new StreamReader("C:\\wamp\\www\\FTCPC\\logfile.txt");
    byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
    sourceStream.Close();
    request.ContentLength = fileContents.Length;

    Stream requestStream = request.GetRequestStream();
    requestStream.Write(fileContents, 0, fileContents.Length);
    requestStream.Close();

    FtpWebResponse response = (FtpWebResponse)request.GetResponse();

    Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

    response.Close();



    Console.WriteLine("\\n");
    Console.ReadLine();

}










谢谢










Thanks

推荐答案

为什么您本质上两次发表相同的问题?顺便说一句,最简单的方法是在服务器上设置Web服务,编写使用该Web服务的代码,然后仅调用Web服务方法来发送文本.
Why did you post the same question twice essentially ? The easiest way to do all this, by the way, is to set up a webservice on your server, write code that uses that web service, and just call the webservice methods to send your text.


创建一个接受文本文件(或仅接受新数据)作为查询字符串一部分的网页,并让其后的网页代码处理服务器端的具体内容.
Create a web page that accepts the text file (or just the new data) as part of the querystring, and let the web page code behind handle the nitty-gritty on the server end.


这篇关于我如何在服务器上更新文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆