String ftpServerIP = "apssdb ";
String ftpUserID = "ebideai ";
String ftpPassword = "ebideai ";
Private void Upload (string filename)
{
FileInfo fileInf = new FileInfo (filename );
String uri = "ftp: //" + ftpServerIP + "/" + fileInf. Name;
FtpWebRequest reqFTP;
ReqFTP = (FtpWebRequest) FtpWebRequest. Create (new Uri ("ftp: //" + ftpServerIP + "/" + fileInf. Name ));
ReqFTP. Credentials = new NetworkCredential (ftpUserID, ftpPassword );
ReqFTP. KeepAlive = false;
ReqFTP. Method = WebRequestMethods. Ftp. UploadFile;
ReqFTP. UseBinary = true;
ReqFTP. ContentLength = fileInf. Length;
Int buffLength = 2048;
Byte [] buff = new byte [buffLength];
Int contentLen;
FileStream fs = fileInf. OpenRead ();
Try
{
Stream strm = reqFTP. GetRequestStream ();
ContentLen = fs. Read (buff, 0, buffLength );
While (contentLen! = 0)
{
Strm. Write (buff, 0, contentLen );
ContentLen = fs. Read (buff, 0, buffLength );
}
Strm. Close ();
Fs. Close ();
MessageBox. Show ("success", "Upload Error ");
}
Catch (Exception ex)
{
MessageBox. Show (ex. Message, "Upload Error ");
}
}
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 buffer size = 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 ();
}
Catch (Exception ex)
{
MessageBox. Show (ex. Message );
}
}
Private void button3_Click (object sender, EventArgs e)
{
OpenFileDialog op = new OpenFileDialog ();
Op. RestoreDirectory = true;
If (DialogResult. OK = op. ShowDialog ())
{
TextBox1.Text = op. FileName;
}
// Upload (textBox1.Text );
Upload (textBox1.Text );
}
Private void button4_Click (object sender, EventArgs e)
{
Download (@ "d:", "table 092.161. SQL ");
}
Http://www.cnblogs.com/kerryking/archive/2007/07/10/813079.aspx