Note that there are some explanatory texts on larger screens.

plurals
  1. POError trying to use C# ftpwebrequest to ftp xml file to Zebra printer
    primarykey
    data
    text
    <p>I've used ZebraDesigner for xml ver2.0 to create some label templates for a Zebra 170PAX4 printer. I've successfully exported the zpl to the Zebra and I can edit and send the xml file to the Zebra using ftp in a Windows command prompt like this:<code>c:\ftp 10.161.41.212 Connected to 10.161.41.212. 220 ZBR-46688 Version 1.01.7 ready. User (10.161.41.212:(none)): 230 User logged in. ftp&gt; put c:SPver1_1.xml 200 PORT command successful. 150 Opening ASCII mode data connection for SPver1_1.xml. 226 Transfer complete. ftp: 324 bytes sent in 0.00Seconds 324000.00Kbytes/sec</code></p> <p>Now, I'm trying to used MS VS2010 and C# to do this automatically from a WinForms application. But for some reason no what I'm seem to try using the FtpWebRequest class, I also receive a error</p> <blockquote> <p>The remote server returned an error: (502) Command not implemented.</p> </blockquote> <p>From what I understand, the ftp method UploadFile is the same as STOR which is the same as the alias put. The code I'm using is shown below: </p> <pre><code>public bool PutXmlFile(CZebraPrinter printer, CDeviceContainer devices) { bool OK = true; CDevice currDevice = new CDevice(); currDevice = devices.GetDevice(this.m_devName); string ftpHost = "ftp://" + printer.m_IPAddress + "/"; string ftpPath = "E:"; Uri printerUri = new Uri(ftpHost + ftpPath); try { FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(printerUri); ftpRequest.Method = WebRequestMethods.Ftp.UploadFile; ftpRequest.KeepAlive = false; ftpRequest.UseBinary = false; ftpRequest.UsePassive = false; ftpRequest.Timeout = 5000; //milliseconds // The Zebra printer uses anonymous login ftpRequest.Credentials = new NetworkCredential("anonymous", ""); // Copy the contents of the file to the request stream. StreamReader sourceStream = new StreamReader(currDevice.m_defaultDataFile); byte[] fileContents = Encoding.ASCII.GetBytes(sourceStream.ReadToEnd()); sourceStream.Close(); Stream requestStream = ftpRequest.GetRequestStream(); requestStream.Write(fileContents, 0, fileContents.Length); requestStream.Close(); FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse(); //Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription); //Check response response.Close(); } catch (Exception ex) { string errMessage = string.Format("An error occured trying to ftp the device xml file to the Zebra printer. \n\nReason:\n{0}", ex.Message); MessageBox.Show(errMessage, m_mfgInfoErr, MessageBoxButtons.OK, MessageBoxIcon.Error); return !OK; } return OK; } </code></pre> <p>Does anyone see what I may be doing wrong. Any ideas would be appreciated. Thanks.</p> <p>I ran the TRACE, here is the output:</p> <pre><code>System.Net Information: 0 : [4780] FtpWebRequest#14993092::.ctor(ftp://10.161.41.212/E:) System.Net Verbose: 0 : [4780] Exiting WebRequest::Create() -&gt; FtpWebRequest#14993092 System.Net Verbose: 0 : [4780] FtpWebRequest#14993092::GetRequestStream() System.Net Information: 0 : [4780] FtpWebRequest#14993092::GetRequestStream(Method=STOR.) System.Net Information: 0 : [4780] Associating FtpWebRequest#14993092 with FtpControlStream#720107 System.Net Information: 0 : [4780] FtpControlStream#720107 - Received response [220 ZBR-46688 Version 1.01.7 ready.] System.Net Information: 0 : [4780] FtpControlStream#720107 - Sending command [USER anonymous] System.Net Information: 0 : [4780] FtpControlStream#720107 - Received response [230 User logged in.] System.Net Information: 0 : [4780] FtpControlStream#720107 - Sending command [OPTS utf8 on] System.Net Information: 0 : [4780] FtpControlStream#720107 - Received response [502 Command 'OPTS' not implemented.] System.Net Information: 0 : [4780] FtpControlStream#720107 - Sending command [PWD] System.Net Information: 0 : [4780] FtpControlStream#720107 - Received response [502 Command 'PWD' not implemented.] System.Net Information: 0 : [4780] FtpWebRequest#14993092::(Releasing FTP connection#720107.) System.Net Error: 0 : [4780] Exception in the FtpWebRequest#14993092::GetRequestStream - The remote server returned an error: (502) Command not implemented. </code></pre> <p>So it looks like <strong>OPTS</strong> and <strong>PWD</strong> are the problem. Is there any way to control what is sent by FtpWebRequest or do I need a 3rd party library?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload