簡體   English   中英

如何從給定的圖像路徑(實時URL)直接將圖像上傳到FTP

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

我正在執行的任務是,需要使用給定實時路徑中的C#編碼將圖像上傳到特定的FTP。

目前,我已經完成了,但是要在FTP上上傳圖像,我需要往返(在本地下載圖像,然后使用代碼將其上傳到現場)。

我希望解決方案直接將圖像上傳到ftp,而無需下載。

例如。 從給定路徑http://www.globalgear.com.au/products/bladesbook_sml.jpg

我需要這張圖片上傳。

您好,我想更正我的問題,我想從此URL(globalgear.com.au/productfeed.xml)提取大小圖像,然后直接上傳到FTP,而無需在本地下載。

請提出任何解決方案。

謝謝謝坦

也許這會起作用:

 // 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