将数据从本地计算机移至服务器 [英] Moving data from my local machine to server
问题描述
大家好,
我需要将一个文本文件从本地系统移动到服务器.为此,我做了一个控制台应用程序.以下是我编写的代码,
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[^]
这篇关于将数据从本地计算机移至服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!