Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# FTP C接收后损坏的存档#_C#_Ftp_Connection - Fatal编程技术网

C# FTP C接收后损坏的存档#

C# FTP C接收后损坏的存档#,c#,ftp,connection,C#,Ftp,Connection,我尝试通过FTP发送一个.zip文件。首先,我获取一个.txt文件并将其添加到archive.zip中 当我尝试发送此文件时,一切正常。但是,当一个文件出现在机器上,我想解压时,.zip文件就坏了。 在发送方机器上.zip文件正常。只有ftp机器上的文件被损坏 using System; using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Linq; using

我尝试通过FTP发送一个.zip文件。首先,我获取一个.txt文件并将其添加到archive.zip中

当我尝试发送此文件时,一切正常。但是,当一个文件出现在机器上,我想解压时,.zip文件就坏了。 在发送方机器上.zip文件正常。只有ftp机器上的文件被损坏

using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;


    namespace SEND_Plovdiv
    {

    public class WebRequestGetExample
    {

        public static void Main()
        {
            string[] lineOfContents = File.ReadAllLines(@"C:\\M\send.txt");

            string username = "";
            string password = "";
            foreach (var line in lineOfContents)
            {
                string[] tokens = line.Split(',');
                string user = tokens[0];
                string pass = tokens[1];

                username = user;
                password = pass;
            }

            string pathFile = @"C:\M\Telegrami\";
            string zipPath = @"C:\M\Plovdiv.zip";

            if (File.Exists(zipPath))
            {
                File.Delete(zipPath);
            }

            ZipFile.CreateFromDirectory(pathFile, zipPath, CompressionLevel.Fastest, false);


            // Get the object used to communicate with the server.
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://199.199.199.199/Plovdiv.zip");
                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.  
                StreamReader sourceStream = new StreamReader(@"C:\M\Plovdiv.zip");
                byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());

                sourceStream.Close();

                request.ContentLength = fileContents.Length;

                Stream requestStream = request.GetRequestStream();
                requestStream.Write(fileContents, 0, fileContents.Length);
                requestStream.Close();

                FtpWebResponse response = (FtpWebResponse)request.GetResponse();

                Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
                Console.ReadKey();

                response.Close();


        }
    }
}
我不知道这部分代码到底是怎么做的:

StreamReader sourceStream = new StreamReader(@"C:\M\Plovdiv.zip");

从使用StreamReader切换到BinaryReader。Zip文件是二进制文件,而不是UTF8

以下是一个示例:

using (FileStream fs = File.Open(@"c:\1.bin",FileMode.Open))
            {
                    byte[] data = new BinaryReader(fs).ReadBytes((int)fs.Length);
                    Encoding.getstring....
            }

ftpServerIP的确切值是多少?你怎么看
ConfigurationManager.AppSettings[“199.199.199.199”]
Dos?我从代码中删除了真实的IP地址,并将其放入199.199.199.199..您需要学会调试自己的代码。我们无法神奇地猜测app.config的外观,也无法查看在运行时使用了哪些值我编辑了我的问题,很抱歉,app.config文件中没有设置。所以我猜问题是,你有一些无效的ip、用户名和密码值。您还应该使用appSettings,而不是appSettings,它们被认为是过时的。