>
سلام
من میخواهم عکسی را از هاست آپلود کنم ولی وقتی به این خط میرسد
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;