public static void UpLoadImage(string source) { try { string filename = System.IO.Path.GetFileName(source); // string ftpfullpath = ftpurl; FtpWebRequest ftp = (FtpWebRequest)WebRequest.Create("ftp://192.168.0.41"); // ftp.Credentials = new NetworkCredential(ftpusername, ftppassword); MessageBox.Show(ftp.GetResponse().ToString()); ftp.KeepAlive = true; ftp.UseBinary = true; ftp.Method = WebRequestMethods.Ftp.UploadFile; FileStream fs = File.OpenRead(source); byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, buffer.Length); fs.Close(); Stream ftpstream = ftp.GetRequestStream(); ftpstream.Write(buffer, 0, buffer.Length); ftpstream.Close(); } catch (Exception ex) { throw ex; } }
private bool isConnectionValid(string url, string user, string password) { try { FtpWebRequest request = (FtpWebRequest)WebRequest.Create(url); request.Method = WebRequestMethods.Ftp.ListDirectory; request.Credentials = new NetworkCredential(user, password); request.GetResponse(); } catch(WebException ex) { return false; } return true; }
FtpWebRequest ftp = (FtpWebRequest)WebRequest.Create("ftp://192.168.0.41/your_file.ext");
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)