private void UploadFile(string filename) { FileInfo fileInfo = new FileInfo(filename); string FileAndFolder = "ftp://" + serverIP + "/" + fileInfo.Name; FtpWebRequest RequestFTP; RequestFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + serverIP + "/" + fileInfo.Name)); RequestFTP.Credentials = new NetworkCredential(username, passwd); RequestFTP.KeepAlive = false; RequestFTP.Method = WebRequestMethods.Ftp.UploadFile; RequestFTP.UseBinary = true; int sizedata = 1024; byte[] data = new byte[sizedata]; int contlenght; FileStream fs = fileInfo.OpenRead(); try { Stream strm = RequestFTP.GetRequestStream(); contlenght = fs.Read(data, 0, sizedata); while (contlenght != 0) { strm.Write(data, 0, contlenght); contlenght = fs.Read(data, 0, sizedata); } strm.Close(); fs.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Upload Fail"); } }
private void btnUpload_Click(object sender, EventArgs e) { String fileName = trwFileExplorer.SelectedNode.ToString(); System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo("C:\\"); System.IO.FileInfo[] files = dir.GetFiles(); System.Collections.ArrayList arrList = new System.Collections.ArrayList(); foreach (System.IO.FileInfo f in files) { fileName = System.IO.Path.GetFullPath(f.Name); } MessageBox.Show(fileName); UploadFile(fileName); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)