بسته

آپلودعکس

2 سال پیش
#4160 نقل قول
سلام
من میخواهم عکسی را از هاست آپلود کنم ولی وقتی به این خط میرسد
Stream ftpStream = ftpRequest.GetRequestStream();

خطا می دهد

            try
            {
                var qP = GetFtp(TypeFtp);

                /* Create an FTP Request */
                FtpWebRequest ftpRequest = (FtpWebRequest)FtpWebRequest.Create(qP.FtpAddress + FileName);
                /* Log in to the FTP Server with the User Name and Password Provided */
                ftpRequest.Credentials = new NetworkCredential(qP.UserName, qP.Password);
                /* When in doubt, use these options */
                ftpRequest.UseBinary = true;
                ftpRequest.UsePassive = true;
                ftpRequest.KeepAlive = true;
                /* Specify the Type of FTP Request */
                ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
                /* Establish Return Communication with the FTP Server */
                Stream ftpStream = ftpRequest.GetRequestStream();
                /* Open a File Stream to Read the File for Upload */
                Stream localFileStream = MyFile;
                /* Buffer for the Downloaded Data */
                // فایل به تکه های دو کیلو بایتی تبدیل میشه که شامل سرعت بالا ولی دست تکانی زیادی است.
                byte[] byteBuffer = new byte[2048];
                int bytesSent = localFileStream.Read(byteBuffer, 0, 2048);
                /* 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, 2048);
                }


                /* Resource Cleanup */
                localFileStream.Close();
                ftpStream.Close();
                ftpRequest = null;

                #region Upload Text Files
                //// Get the object used to communicate with the server.  
                //FtpWebRequest Myrequest = (FtpWebRequest)WebRequest.Create(qP.FtpAddress + FileName);
                //Myrequest.Method = WebRequestMethods.Ftp.UploadFile;

                //        // This example assumes the FTP site uses anonymous logon.  
                //        Myrequest.Credentials = new NetworkCredential(qP.UserName, qP.Password);

                //// Copy the contents of the file to the request stream.  
                //StreamReader sourceStream = new StreamReader(MyFile);
                ////کار با فایلهایی با حجم ۲ ۳کیلو بایت و فایل های متنی
                ////    byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
                //sourceStream.Close();
                //        Myrequest.ContentLength = fileContents.Length;

                //        Stream requestStream = Myrequest.GetRequestStream();
                //requestStream.Write(fileContents, 0, fileContents.Length);
                //        requestStream.Close();

                //        FtpWebResponse response = (FtpWebResponse)Myrequest.GetResponse();

                ////Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

                //response.Close();

                #endregion
                return qP.FtpID;
            }
            catch (Exception e)
            {

                return -1;
        

کدها رو از MSDN برداشتم، چند ماه پیش کار میکرد الان نمیدونم چرا کار نمیکند.
ممکنه راهنماییم کنید؟
0
2 سال پیش
#4172 نقل قول
وقتی عکس را بارگذاری میکنید عبارت '' عکس مورد نظر شما پیدا نشد'' میدهد؟
1
2 سال پیش
#4182 نقل قول
بله دقیقا همین را مینویسد
0
2 سال پیش
#4188 نقل قول
احتمالا اطلاعات ftp که وارد میکنید اشتباه است و یوزر و پسورد ftp برای ftp کاربر محسوب میشود
برایامتحان درستی کد ftp ببینید مستقیم می ‌توانید با همین اطلاعات به ftp وصل بشید یا نه
1
2 سال پیش
#4200 نقل قول
جای اسم و پسورد رو توی فیلدهای دیتابیس اشتباه وارد کرده بودم
0
2 سال پیش
#4205 نقل قول
بسیار سپاس از کمکتون
0
دسته بندی ها