Click here to Skip to main content
15,896,489 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have written below code for uploading files to ftp but getting exception as value cannot be null and parameter name path, not sure where i am wrong yesterday uploaded files with same code but today getting exception. please help.

What I have tried:

 FtpWebRequest request = (FtpWebRequest)WebRequest.Create(FTPFullPath +"\\"+ Path.GetFileName(Renamefiles[i]));
 request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = newnetworkCredential(myftpcreds.UserName,myftpcreds.Password);
 byte[] filecontents;//unable to read bytes
     using (StreamReader sourceStream = new StreamReader(Renamefiles[i]))
         {
    filecontents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());                             }
   request.ContentLength = filecontents.Length;
   using (Stream requestStream = request.GetRequestStream())
  {
      requestStream.Write(filecontents, 0, filecontents.Length);
     }
Posted
Updated 1-Aug-18 19:36pm

1 solution

We can't tell - we have no access to your app while it is running, and you need that to start looking at the problem because what is in the various variables is key to the problem.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!


BTW: If you are trying to transfer files, doing use any encoding: read the files as byte streams instead. Encoding as UTF8 or anything else can alter file content (as not all values are encodable) and damage non-text files in the transfer process. Using bytes means all data is transfered as is, and unchanged.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900