111,120
社区成员
发帖
与我相关
我的任务
分享
private void Download(string filePath, string fileName)
{
FtpWebRequest reqFTP;
try
{
FileStream outputStream = new FileStream(filePath + "\\" + fileName, FileMode.Create);
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + fileName));
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();
long cl = response.ContentLength;
int bufferSize = 2048;
int readCount;
byte[] buffer = new byte[bufferSize];
readCount = ftpStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
outputStream.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);
}
ftpStream.Close();
outputStream.Close();
response.Close();
ftpStream.Dispose();
outputStream.Dispose();
GC.SuppressFinalize(this);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
string filePathAndName = "E:\\StuPhoto" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + ".jpg";
Download("E:\\StuPhoto", this.txtSearchInputStuID.Text + ".jpg");
System.Drawing.Image tempStuPhoto = (System.Drawing.Image)(Bitmap.FromFile(("E:\\StuPhoto\\" + this.txtSearchInputStuID.Text + ".jpg")));
System.Drawing.Image stuPhoto = (System.Drawing.Image)(tempStuPhoto.Clone());
tempStuPhoto.Dispose();
this.picBoxStuPhoto.Image = stuPhoto;