本文介绍了如何在FTP服务器上传文件和加密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 已编写下面的代码将文件从本地系统复制到ftp服务器,同样我需要选择多个文件并将其上传到服务器中。当我上传文件时,它应该被转换为加密文件,任何建议,我也写了加密代码。 我尝试过: 公共类WebRequestGetExample { public static void Main() { //获取用于与服务器通信的对象。 FtpWebRequest request =(FtpWebRequest)WebRequest.Create(ftp://192.1....../ftp.txt); request.Method = WebRequestMethods.Ftp.UploadFile; //此示例假定FTP站点使用匿名登录。 request.Credentials = new NetworkCredential(username,password); //将文件内容复制到请求流。 byte [] fileContents; 使用(StreamReader sourceStream = new StreamReader(E:\\Anusha \\\\\ [@]) { fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd) ()); } request.ContentLength = fileContents.Length; using(Stream requestStream = request.GetRequestStream()) { requestStream.Write(fileContents,0,fileContents.Length); } 使用(FtpWebResponse response =(FtpWebResponse)request.GetResponse()) { Console.WriteLine(上传文件完成,状态{0},response.StatusDescription ); } } } 解决方案 have written below code to copy file from local system to ftp server , similarly i need to select multiple files and upload them in server . While i upload the files it should be converted as encrypted files, any suggestions, i have written code for encryption also.What I have tried:public class WebRequestGetExample{public static void Main (){// Get the object used to communicate with the server.FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://192.1....../ftp.txt"); request.Method =WebRequestMethods.Ftp.UploadFile;// This example assumes the FTP site uses anonymous logon.request.Credentials = new NetworkCredential("username", "password");// Copy the contents of the file to the request stream.byte[] fileContents;using (StreamReader sourceStream = new StreamReader("E:\\Anusha\\ftp.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 {0}", response.StatusDescription);}}} 解决方案 这篇关于如何在FTP服务器上传文件和加密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-28 11:17