在ftp中上传文件时,获取异常值不能为null [英] Getting exception value cannot be null while uploading files in ftp

查看:344
本文介绍了在ftp中上传文件时,获取异常值不能为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我写了以下代码,用于将文件上传到ftp但是因为值不能为null而且参数名称路径不正确,不知道我错在哪里昨天上传了相同代码的文件但是今天得到例外。请帮忙。



我的尝试:



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);
     }

推荐答案

我们无法分辨 - 我们无法在您的应用运行时访问您的应用,并且您需要开始查看问题,因为各种变量中的问题是问题的关键。



所以,这取决于你。

幸运的是,你有一个工具可以帮助你找到正在发生的事情:调试器。



在函数的第一行放置一个断点,然后通过调试器运行代码。然后查看您的代码,并查看您的数据并找出手动应该发生的事情。然后单步执行每一行检查您预期发生的情况正是如此。如果不是,那就是当你遇到问题时,你可以回溯(或者再次运行并仔细观察)以找出原因。


对不起,但我们不能为你做到这一点 - 时间让你学习一门新的(非常非常有用的)技能:调试!





BTW:如果您尝试传输文件,请使用任何编码:将文件读取为字节流。编码为UTF8或其他任何内容都可以更改文件内容(因为并非所有值都可编码)并在传输过程中损坏非文本文件。使用字节意味着所有数据按原样传输,并保持不变。
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.


这篇关于在ftp中上传文件时,获取异常值不能为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆