title: Getting "Invalid URL" when uploading file using FtpWebRequest
body: <p>We have an OpenVMS (VMS) Alpha server which I need to access in order for me to transfer a file via FTP. The problem is that it does not support the command used in <code>FtpWebRequest</code> when initiating the connection (<a href="ftp://192.168.xx.xx" rel="nofollow noreferrer">ftp://192.168.xx.xx</a>), is there any other FTP function that I may used aside from FtpWebRequest? </p>
  
  <p>I've been using my code on Windows and Unix environment before but this is my first time to do it on a VMS OS, I can also access the server via FTP using the command prompt.</p>
  
  <p>Below is my code:</p>
  
  <pre><code>//Initializing ftp request
  ftp ftpClient = new ftp(@"ftp://192.168.xx.xx/", "username", "password");
  MessageBox.Show((ftpClient.upload("FILE.TAB", @"C:\FILE.TAB")).ToString());
  
  public ftp(string hostIP, string userName, string password)
      {
          host = hostIP; user = userName; pass = password;
      }
  public string upload(string remoteFile, string localFile)
      {
          try
          {
              /* Create an FTP Request */
              ftpRequest = (FtpWebRequest)FtpWebRequest.Create(host +  remoteFile);
              /* Log in to the FTP Server with the User Name and Password Provided */
              ftpRequest.Credentials = new NetworkCredential(user, pass);
              ///* When in doubt, use these options */
              ftpRequest.UseBinary = false;
              ftpRequest.UsePassive = true;
              ftpRequest.KeepAlive = true;
  
              /* Specify the Type of FTP Request */
              ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
              /* Establish Return Communication with the FTP Server */
              ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
              ftpStream = ftpRequest.GetRequestStream();
              /* Open a File Stream to Read the File for Upload */
              FileStream localFileStream = new FileStream(localFile, FileMode.Open);
              /* Buffer for the Downloaded Data */
              byte[] byteBuffer = new byte[bufferSize];
              int bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize);
              /* Upload the File by Sending the Buffered Data Until the Transfer is Complete */
  
              while (bytesSent != 0)
              {
                  ftpStream.Write(byteBuffer, 0, bytesSent);
                  bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize);
              }
  
              /* Resource Cleanup */
              localFileStream.Close();
              ftpStream.Close();
              ftpRequest = null;
              return "0";
  
          }
          catch (Exception ex) { return ex.ToString(); }
          //return 1;
      }
  </code></pre>
  
  <p>The error I get on the above code is "Invalid URL....".</p>
  
  <p>while the error I get when I try to run it on a browser:
  <img src="https://i.stack.imgur.com/R3rgi.jpg" alt="enter image description here"></p>
  
  <p>But I can connect using the usual cmd command in windows:
  <img src="https://i.stack.imgur.com/BOk55.jpg" alt="enter image description here"></p>
  
  <p>Any suggestions??</p>