title: Use C# to FTP file to mainframe including dataset - Translate FTP script to FtpWebRequest code
body: <p>I use a cmd (Windows) to send file to an IBM Mainframe and works fine it's something like this:</p>
  
  <pre class="lang-none prettyprint-override"><code>Open abc.wyx.state.aa.bb
  User
  Pass
  lcd c:\Transfer&gt;
  Put examplefile 'ABCD.AA.C58FC.ABC1FD.ZP3ABC'
  close
  bye
  </code></pre>
  
  <p>I need to convert this to C#. I have been trying using <code>FtpWebRequest</code> but no luck. I cannot figure out how include the dataset I guess. When I run the application I got the following error:</p>
  
  <blockquote>
    <p>((System.Exception)(ex)).Message "The remote server returned an error: (550) File unavailable (e.g., file not found, no access)."
    550 Unable to store
    The remote server returned an error: (550) File unavailable (e.g., file not found, no access).</p>
    
    <p>((FtpWebResponse)ex.Response).StatusDescription "550 Unable to store /'ABCD.AA.C58FC.ABC1FD.ZP3ABC/examplefile'\r\n"</p>
  </blockquote>
  
  <p>Here is what I got in C#</p>
  
  <pre><code>string user = "user";
  string pwd = "password";
  
  string ftpfullpath = @"ftp://abc.wyx.state.aa.bb//'ABCD.AA.C58FC.ABC1FD.ZP3ABC'/examplefile'";
  
  try
  {
       FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
       ftp.Credentials = new NetworkCredential(user, pwd);
  
       ftp.KeepAlive = true;
       ftp.UseBinary = false;  //Use ascii.              
  
       ftp.Method = WebRequestMethods.Ftp.UploadFile;
  
       FileStream fs = File.OpenRead(inputfilepath);
       byte[] buffer = new byte[fs.Length];
       fs.Read(buffer, 0, buffer.Length);
       fs.Close();
  
       Stream ftpstream = ftp.GetRequestStream();
       ftpstream.Write(buffer, 0, buffer.Length);
       ftpstream.Close();
  }
  catch (WebException ex)
  {
       String status = ((FtpWebResponse)ex.Response).StatusDescription;
       throw new Exception(status);
  }
  </code></pre>