L
L
LebedevStr2020-05-19 15:31:54
FTP
LebedevStr, 2020-05-19 15:31:54

How to upload a file to FTP (C#)?

There is this code:

string username = "username";
   string Pass = "pass";
   string URLpath = "ftp://serv.name/";
   //string filePath = @"C:\somefile.txt";
   try {
       //filePath = FullPath.Text;
    string filePath = @"C:\somefile.txt";
    using(WebClient client = new WebClient()) {
     client.Credentials = new NetworkCredential(username, Pass);
     client.BaseAddress = URLpath;
     client.UploadFile(WebRequestMethods.Ftp.UploadFile, filePath);
    }
   }

    catch (Exception ex)
        {
            MessageBox(ex.Message, ex.Source);
        }


The code itself works without errors.
But the FTP file is not uploading.

And yes, this is an example from the Internet - I can’t understand how to specify the path to which directory to upload the file.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-05-19
@LebedevStr

how to specify the path to which directory to upload the file

The first argument UploadFileis just the path where to put the file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question