English 中文(简体)
FTP 文件发送错误错误
原标题:FTP file send incorrectly
  • 时间:2012-05-25 06:27:46
  •  标签:
  • ftp

我们有一个标签打印机 A4+, 我们用它们打印我们的仓库的标签。 我们想要打印一个巨大的标签, 我们的仓库 A4+, 我们想要打印一个标签, 每一个都是来自另一个的, 我们决定为每个打印任务打印 DBF 文件, 所以每次 DBF 文件包含 diffrent 记录的数量, 然后我们的网络服务会向 A4+ 打印机提出ftp 请求, 然后将 DBF 文件输入打印机, 然后打印命令发送到打印机, DBF 文件会打印。 大多数时候, 所有步骤都成功运行, 但打印机上的 DBF 文件有时只是从 Dbf 文件上略作 diffrent, 而 Diffrence 是在文件的页头上, 所以每次 DBFF 文件都含有 diffrent 的编号, 而 DBF 文件没有被打印到 DBF 文件的末尾, 例如, 如果 DBF 文件包含500 记录, 打印机只打印300 记录或 diffrent 文件, 然后它会继续打印, 但标签上没有数据, 它意味着在300 打印机上读 dbf 文件, 和标签标签是相当原始的 。 因为F 继续打印到 DBF 。

我们比较了网络服务主机服务器上的 DBF 文件( 这是我们创建 dbf 文件的地方) 和打印机上的ftp 的文件, 它们是一样的, 文件页眉上只有一点点是 diffrent, 它制造了这个问题 。

i 包括我们制作 DBF 文件的代码, 以及我们用来将此文件输入打印机的代码, 还有我同时附上两个 DBF 文件作为样本 。

我们的团队在这个项目上工作, 我们在你的网站上研究帮助, 但是现在我们可以看到一切都很好, 我们可以调试这个案子, 也许你可以帮助我们解决这个问题。

- - - - - - - - - - - - - - Create DBF档案 -

   private bool EportDBF(string filePath, List<BarcodeData> list)
   {
       string tableName = string.Empty;
       string folderPath = string.Empty;

       GetFileNameAndPath(filePath, ref tableName, ref folderPath);

       string connString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + folderPath + "; Extended Properties=DBASE IV;";
       string createStatement = "Create Table " + tableName + " ( ";
       string insertStatement = "Insert Into " + tableName + " Values ( ";
       string insertTemp = string.Empty;

       OleDbConnection conn = new OleDbConnection(connString);

       try
       {

           createStatement += "[RW] varchar(4), ";
           createStatement += "[CODE] varchar(16), ";
           createStatement += "[DESC] varchar(16), ";
           createStatement += "[WEIGHT] varchar(16), ";
           createStatement += "[DATE] varchar(32), ";
           createStatement += "[RCODE] varchar(16), ";
           createStatement += "[BCODE] varchar(16) )";

           conn.Open();

           DataSet dsFill = new DataSet();

           OleDbDataAdapter daInsertTable = new OleDbDataAdapter(createStatement, conn);

           daInsertTable.Fill(dsFill);

           int row = 1001;

           foreach (var item in list)
           {
               insertTemp = insertStatement;

               insertTemp += " " + row++ + "  , ";
               insertTemp += " " + item.ItemCode + "  , ";
               insertTemp += " 0  , ";
               insertTemp += " " + item.Weight + "  , ";
               insertTemp += " " + item.DateTime + "  , ";
               insertTemp += " " + item.ReferenceCode + "  , ";
               insertTemp += " " + item.Barcode.ToString() + "  ) ;";

               daInsertTable = new OleDbDataAdapter(insertTemp, conn);

               daInsertTable.Fill(dsFill);
           }

           conn.Close();
           conn.Dispose();
       }
       catch (Exception ex)
       {
           conn.Close();
           conn.Dispose();

           return false;
       }

       return true;
   }

- - - - - - - - - - -FTP DBF档案 -

   private bool UpLoadDBF(List<BarcodeData> barcodeDatas, string path)
   {
       try
       {
           EportDBF(path, barcodeDatas);

           FtpWebRequest request;
           FtpWebResponse response;

           Stream sourceStream = new MemoryStream();
           Stream requestStream = sourceStream;
           StreamReader reader = new StreamReader(path);

           try
           {
               request = (FtpWebRequest)WebRequest.Create("ftp://" + printerIP + "/card/barcodes.dbf");
               request.Method = WebRequestMethods.Ftp.UploadFile;
               request.KeepAlive = false;
               request.Credentials = new NetworkCredential(user, password);

               byte[] byteArray = Encoding.Default.GetBytes(reader.ReadToEnd());
               sourceStream = new MemoryStream(byteArray);

               try
               {
                   requestStream = request.GetRequestStream();
               }
               finally 
               {
                   request.ContentLength = sourceStream.Length;

                   byte[] buffer = new byte[sourceStream.Length];
                   int count = 2048;
                   if (sourceStream.Length < count)
                       count = (int) sourceStream.Length;

                   int bytesRead = sourceStream.Read(buffer, 0, count);

                   do
                   {
                       requestStream.Write(buffer, 0, bytesRead);
                       bytesRead = sourceStream.Read(buffer, 0, count);

                   } while (bytesRead > 0);

                   sourceStream.Close();
                   requestStream.Close();
               }
           }
           catch (Exception ex)
           {
           }
           finally
           {
               request = null;

               sourceStream.Close();
               sourceStream.Dispose();

               reader.Close();
               reader.Dispose();

               requestStream.Close();
               requestStream.Dispose();
           }
       }
       catch (Exception ex)
       {
           return false;
       }

       return true;
   }

所以多多谢多谢不前

最佳回答

我知道你为什么使用编码。 Default. getBytes 阅读字节。 而不是使用 FileStream S Read 方法来阅读字节。 希望这有帮助 。

问题回答

暂无回答




相关问题
What is the simplest way to create my own FTP server?

What is the simplest way to create my own FTP server in C#? Some of the folders will be virtual folders. The authentication should be from a SQL Server database, which includes tables of the ASP.NET ...

FTP In/Out Folder Name Best Practices

What best practices (if any) do you adhere to regarding setting up outgoing and incoming folders for your FTP clients? We typically use "outgoing" and "incoming", but no matter how you phrase the ...

Using TCPClient with RAW FTP to retrieve file

I get the following message back when trying to retrieve a file using TCPClient and RAW FTP: 425 Failed to establish connection. I connect using : using (TcpClient client = new TcpClient("...

Retrieving a List of Files from an FTP server in C#

I m trying to retrieve a list of files from an FTP server, but I m getting some weird non-ASCII responses. Here is the code that I am using: public string[] getFileList(string mask) { if(!...

FTP error on Quit command

I m using a ftp library that causes an error sending the quit command. It seems that the character before QUIT is not recognized. I took a look at the code but didn t find anything. 500 ?QUIT : ...

Passive FTP Timeout while using WinINet

I m trying to ftp a file using passive ftp but I get a timeout (12002) when the put command is called. I m able to use passive ftp with other ftp sites but not this new one. I ve tried this using ...

热门标签