将数据从本地计算机移至服务器

编程入门 行业动态 更新时间:2024-10-26 02:34:38
本文介绍了将数据从本地计算机移至服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 我需要将一个文本文件从本地系统移动到服务器.为此,我做了一个控制台应用程序.以下是我编写的代码,

HI all, i need to move one text file from my local system to a server.for that i did one console application.the following is the code i wrote,

using System; using System.IO; using System.Net; using System.Text; namespace FileTransfer { class Program { public static void Main() { string ftppath = "ftp://149.223.26.33//D://Developers/muralim/TRW.HRM.Headcount_LMSFeed/Log/"; FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftppath + @"/" + "employeedetails1.txt");//this is the text file i need to copy to the server. request.Method = WebRequestMethods.Ftp.UploadFile; request.Credentials = new NetworkCredential("rajeshb", "Satyam*03"); request.Timeout = 1000000000; StreamReader sourceStream = new StreamReader(@"C:\Documents and Settings\aj99823\Desktop\project\employeedetails1.txt");//this is the current path of the file in the local machine byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd()); sourceStream.Close(); request.ContentLength = fileContents.Length; request.Proxy = null; 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(); } } }

但是在执行过程中,我遇到一个错误,提示基础连接已关闭:接收时发生意外错误.".我认为此错误是由于连接超时问题而发生的.但是我将连接超时时间设置为最大.仍然它给相同的error.now我认为问题将是关于ftp URI" ftp://149.223.26.33//D://Developers/muralim/TRW.HRM.Headcount_LMSFeed/Log/.我认为这不是通往道路的方法.任何人都可以在这方面帮助我.... ????? [edit]已添加代码块-OriginalGriff [/edit]

but while executing i am getting one error saying "The underlying connection was closed: An unexpected error occurred on a receive.".i thought this error occours because of the connection timeout issue.but i gave the connection timeout period to its maximum.but still its giving the same error.now i think the problem will be regarding the the ftp URI that is " "ftp://149.223.26.33//D://Developers/muralim/TRW.HRM.Headcount_LMSFeed/Log/".i think this is not the way to give the path.can anyone plss help me on this....????? [edit]Code block added - OriginalGriff[/edit]

推荐答案

签出. C#FTP客户端库 [ ^ ] check this out. C# FTP Client Library[^]

更多推荐

将数据从本地计算机移至服务器

本文发布于:2023-10-17 02:55:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1499565.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:移至   服务器   计算机   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!