简体   繁体   English

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

[英]How do I directly upload the images to FTP from the given image path(Live URL)

I am working on the task that, I need to upload the images to particular FTP by using C# coding from given live path. 我正在执行的任务是,需要使用给定实时路径中的C#编码将图像上传到特定的FTP。

At the moment I done it, but to upload images on FTP I take round trip of (download the images on local and then upload it to live by using code). 目前,我已经完成了,但是要在FTP上上传图像,我需要往返(在本地下载图像,然后使用代码将其上传到现场)。

I want the solution to directly upload images to to ftp without downloading it. 我希望解决方案直接将图像上传到ftp,而无需下载。

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

I need this image to upload. 我需要这张图片上传。

hello, I am rectifying my question more, I want to fetch Small and large images from this URL(globalgear.com.au/productfeed.xml) and upload directly to FTP without downloading it on local. 您好,我想更正我的问题,我想从此URL(globalgear.com.au/productfeed.xml)提取大小图像,然后直接上传到FTP,而无需在本地下载。

Please suggest any solution. 请提出任何解决方案。

Thanks Chetan 谢谢谢坦

Perhabs this will work: 也许这会起作用:

 // 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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM