CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: WebRequestMethods.Ftp.UploadFile works , nor error, but

  1. #1
    Join Date
    Aug 2015
    Posts
    59

    Question WebRequestMethods.Ftp.UploadFile works , nor error, but

    Does anyone have an idea whats wrong or whats left. I never got an error message, but the file is finally not in my webspace.
    I search around, looking if this code needs something else, but there isnt.

    Code:
     private void btnDownloadTest_Click(object sender, EventArgs e)
       {
           string strPath = string.Empty;
           FtpWebRequest reqFTP = null; 
                   
              try
                  {
                      strPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
    
                      if (File.Exists(strPath + "\\MyCert.cer"))
                      {
                          strPath = Path.Combine(strPath, "MyCert.cer");
                      }
                      else
                      {
                          MessageBox.Show("File does not exist");
                          return;
                      }
                    
                      FileStream myStream = new FileStream(strPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                      reqFTP = (FtpWebRequest)WebRequest.Create("ftp://www.MyWebSpace.net//MyFolder//Subfolder");
                      reqFTP.EnableSsl = true;
                      reqFTP.Method = WebRequestMethods.Ftp.UploadFile;                 
                      reqFTP.KeepAlive = false;
                      reqFTP.Credentials = new NetworkCredential("FtpUser", "FtpKeyword");
                     
                  }
    
                  catch (IOException ex)
                  {
                      MessageBox.Show(ex.TargetSite + "  " + ex.Message);
                  }
    
                  catch (Exception ex)
                  {
                      MessageBox.Show(ex.TargetSite + "  " + ex.Message);
                  }
            }

  2. #2
    Arjay's Avatar
    Arjay is online now Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,460

    Re: WebRequestMethods.Ftp.UploadFile works , nor error, but

    Quote Originally Posted by pschulz View Post
    Does anyone have an idea whats wrong or whats left. I never got an error message, but the file is finally not in my webspace.
    I search around, looking if this code needs something else, but there isnt.

    Code:
     private void btnDownloadTest_Click(object sender, EventArgs e)
       {
           string strPath = string.Empty;
           FtpWebRequest reqFTP = null; 
                   
              try
                  {
                      strPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
    
                      if (File.Exists(strPath + "\\MyCert.cer"))
                      {
                          strPath = Path.Combine(strPath, "MyCert.cer");
                      }
                      else
                      {
                          MessageBox.Show("File does not exist");
                          return;
                      }
                    
                      FileStream myStream = new FileStream(strPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                      reqFTP = (FtpWebRequest)WebRequest.Create("ftp://www.MyWebSpace.net//MyFolder//Subfolder");
                      reqFTP.EnableSsl = true;
                      reqFTP.Method = WebRequestMethods.Ftp.UploadFile;                 
                      reqFTP.KeepAlive = false;
                      reqFTP.Credentials = new NetworkCredential("FtpUser", "FtpKeyword");
                     
                  }
    
                  catch (IOException ex)
                  {
                      MessageBox.Show(ex.TargetSite + "  " + ex.Message);
                  }
    
                  catch (Exception ex)
                  {
                      MessageBox.Show(ex.TargetSite + "  " + ex.Message);
                  }
            }
    Is the path valid?

    Code:
    "ftp://www.MyWebSpace.net//MyFolder//Subfolder"
    Looks like it contains some extra forward slashes.

  3. #3
    Join Date
    Aug 2015
    Posts
    59

    Re: WebRequestMethods.Ftp.UploadFile works , nor error, but

    If I use any custom tool to upload or download a file to my webspace, it goes.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)