Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

.net Core upload File by WebClient FTP

$
0
0

Hi all,

So, I'm trying to upload a file from my client pc to my webserver using a .net core web API. This works fine when I run the web service locally (meaning that the source file and the service are running on the same machine). But when I run the .net core api on my webserver, it cannot find my client computer's local file despite it being fully spelled out. I understand that the API is looking for the file on the webserver at that point, but I'm trying to figure out how to get the webserver to look on my client computer to upload the file when I give it a path. 

Here is my code as it stands. Again, there is no problem writing to the server, only in finding the client computer's file.

  string fileLocation = @"C:\Temp\Test.txt";
            string fileDestination = "ftp://aaa.com//Test//Test.txt";

            try
            {
                // AsynchronousFtpUpLoader.Upload(fileDestination, fileLocation, ftpUserName,  ftpPassword);

               
                string To = "ftp://MyIPGoesHere/directory/Test.txt";
using (WebClient client = new WebClient()) { client.Credentials = new NetworkCredential(ftpUserName, ftpPassword); client.UploadFile(fileDestination, WebRequestMethods.Ftp.UploadFile, fileLocation); } } catch (Exception ex) { return BadRequest(new { message = ex.Message + " : " + ex.InnerException }); }

The error I get is "

An exception occurred during a WebClient request. : System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\\Temp\\Test.txt'.\r\n 

I've seen a lot of posts about this, but never seem to find a clear solution. So I'm sorry if this has been answered elsewhere simply. 

Thanks in advance!
 


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>