void prosesFtp() {
try
{
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpAddress+ftpDir + FileName);
request.Method = WebRequestMethods.Ftp.UploadFile;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential(ftpUser, ftpPassword);
// Copy the contents of the file to the request stream.
/*
StreamReader sourceStream = new StreamReader(appPath + FileName);
byte[] fileContents = Encoding.ASCII.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
*/
byte[] fileContents = File.ReadAllBytes(appPath + FileName);
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
label1.Text = "Kirim Data selesai, status :" + response.StatusDescription;
response.Close();
}
catch (WebException e)
{
label1.Text = "Kirim Data Gagal." + " Status :" + e.Message;
if (e.Status == WebExceptionStatus.ProtocolError)
{
label1.Text = "Kirim Data Gagal.";
label1.Text = label1.Text+"Status Code : "+((FtpWebResponse)e.Response).StatusCode;
label1.Text = label1.Text + "Status Description : " + ((FtpWebResponse)e.Response).StatusDescription;
}
}
catch (Exception e)
{
label1.Text = "Kirim Data Gagal."+e.Message;
}
}
to send non text file.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.