Answered FTP from my application

  • 9. března 2012 18:00
     
      Obsahuje kód

    I have been looking around and trying different samples on allowing FTP access within my app to upload a file or files..

    and no matter what sample i try, i get the following message..

    {"The remote server returned an error: (550) File unavailable (e.g., file not found, no access)."}

    right now im working with a very simple form..

    opendialog control, and 2 buttons.. it opens the dialog window, you select your file and then hit the upload..

    dont think you can get more simple than that..

    The error message comes up on this line:

            private void btnUpload_Click(object sender, EventArgs e)
            {
                string upURL = "ftp://ftp.site.com/";
                FileInfo toUpload = new FileInfo(textBox1.Text);
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(upURL + "/" + textBox1.Text);
                request.Method = WebRequestMethods.Ftp.UploadFile;
                // This example assumes the FTP site uses anonymous logon.
                request.Credentials = new NetworkCredential("login", "password");
                Stream ftpStream = request.GetRequestStream();  <<<---- Error shows up on this line
                FileStream file = File.OpenRead(textBox1.Text);
                int length = 1024;
                byte[] buffer = new byte[length];
                int bytesRead = 0;
                do
                {
                    bytesRead = file.Read(buffer, 0, length);
                    ftpStream.Write(buffer, 0, bytesRead);
                }
                while (bytesRead != 0);
                file.Close();
                ftpStream.Close();
                MessageBox.Show("Upload Complete!");
            }

Všechny reakce