דוגמת קוד שכתב אחי יוסי גולדברג להעלאת קבצים ל - ftp
string url = "ftpUrl/FileName";FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(url); request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("user name", "password");
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false; byte[] buffer = File.ReadAllBytes("path");using (Stream reqStream = request.GetRequestStream())
{
reqStream.Write(buffer, 0, buffer.Length);
}
request.Credentials = new NetworkCredential("user name", "password");
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false; byte[] buffer = File.ReadAllBytes("path");using (Stream reqStream = request.GetRequestStream())
{
reqStream.Write(buffer, 0, buffer.Length);
}
אם לא רוצים לקרוא את כל הקובץ בבת אחת אפשר כמובן לכתוב ככה
using (Stream reqStream = request.GetRequestStream())
{
int count = 0;
byte[] buffer = new byte[100];
using (FileStream file = new FileStream("FileName", FileMode.Open))
{
while ((count = file.Read(buffer, 0, 100)) > 0)
{
reqStream.Write(buffer, 0, count);
}
}
}Read more: שלמה גולדברג
{
int count = 0;
byte[] buffer = new byte[100];
using (FileStream file = new FileStream("FileName", FileMode.Open))
{
while ((count = file.Read(buffer, 0, 100)) > 0)
{
reqStream.Write(buffer, 0, count);
}
}
}Read more: שלמה גולדברג
0 comments:
Post a Comment