I have created my FTP (ftp://xyz.in) with user id and credentials. I have created an asp.net core API application that will copy files from FTP to Azure blob storage. I have my API solution placed in C://Test2/Test2 folder. Now below is my code :
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp:/xyz.in"); request.Method = WebRequestMethods.Ftp.UploadFile; // This example assumes the FTP site uses anonymous logon. request.Credentials = new NetworkCredential("pqr@efg.com", "lmn"); // Copy the contents of the file to the request stream. byte[] fileContents; // Getting error in below line. using (StreamReader sourceStream = new StreamReader("ftp://xyz.in/abc.txt")) { fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd()); } request.ContentLength = fileContents.Length; using (Stream requestStream = request.GetRequestStream()) { requestStream.Write(fileContents, 0, fileContents.Length); } using (FtpWebResponse response = (FtpWebResponse)request.GetResponse()) { Console.WriteLine($"Upload File Complete, status {response.StatusDescription}"); } But on line using (StreamReader sourceStream = new StreamReader("ftp://xyz.in/abc.txt"))
I am getting error : System.IO.IOException: 'The filename, directory name, or volume label syntax is incorrect : 'C:\Test2\Test2\ftp:\xyz.in\abc.txt''
I am not able to understand from where does 'C:\Test2\Test2' string gets append to my FTP. Test2 is a folder where my .Net Core application is placed.
https://stackoverflow.com/questions/65589679/copying-files-from-ftp-to-azure-blob-storage January 06, 2021 at 11:09AM
没有评论:
发表评论