Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static bool uploadtoftp(string localfile, String filename)
- {
- try
- {
- Console.WriteLine("Uploading file to :" + FTPHost + FTPResultDirectory + filename);
- FtpWebRequest request = (FtpWebRequest)WebRequest.Create(FTPHost + FTPResultDirectory + filename);
- request.Method = WebRequestMethods.Ftp.UploadFile;
- request.UseBinary = true;
- request.UsePassive = true;
- request.KeepAlive = true;
- request.Credentials = new NetworkCredential(FTPUsername, FTPPassword);
- using (FileStream fs = File.OpenRead(@localfile))
- {
- byte[] buffer = new byte[fs.Length];
- fs.Read(buffer, 0, buffer.Length);
- fs.Close();
- Stream requestStream = request.GetRequestStream();
- requestStream.Write(buffer, 0, buffer.Length);
- requestStream.Flush();
- requestStream.Close();
- FtpWebResponse response = (FtpWebResponse)request.GetResponse();
- Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
- response.Close();
- Console.WriteLine("Success Upload File to FTP");
- }
- return true;
- }
- catch (Exception e)
- {
- Console.WriteLine("Failed Upload File to FTP");
- Console.WriteLine(e);
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement