如何从给定的图像路径直接将图像上传到FTP(实时URL)

时间:2012-04-30 06:04:19

标签: c# asp.net xml

我正在完成的任务是,我需要使用来自给定实时路径的C#编码将图像上传到特定的FTP。

在我完成它的那一刻,但是要在FTP上传图像我会往返(下载图像 在本地,然后使用代码将其上传到实时。

我希望解决方案直接将图像上传到ftp而不下载。

例如。从给定路径http://www.globalgear.com.au/products/bladesbook_sml.jpg

我需要上传此图片。

你好,我正在纠正我的问题,我想从这个URL(globalgear.com.au/productfeed.xml)中获取小图像和大图像,并直接上传到FTP而不在本地下载。 -

请建议任何解决方案。

由于 阿赫亚

1 个答案:

答案 0 :(得分:0)

Perhabs这将起作用:

 // 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 ("anonymous","janeDoe@contoso.com");

    // Copy the contents of the file to the request stream.
    StreamReader sourceStream = new StreamReader("testfile.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();
相关问题