Your technology certification is waiting. Enroll in Cloud Class ®
protected void cmdUploadFiles_Click(object sender, EventArgs e)
// Upload files from the local machine to the FTP Site
// Get the object used to communicate with the server.
string strUriTarget = "ftp://ftp.StockPickerMax.com/Data/";
// Get source and destination file names
string strArrayTarget = new string;
strArrayTarget = strUriTarget + "AMEX.txt";
strArrayTarget = strUriTarget + "NASDAQ.txt";
strArrayTarget = strUriTarget + "NYSE.txt";
string strArraySource = new string;
strArraySource = "AMEX.txt";
strArraySource = "NASDAQ.txt";
strArraySource = "NYSE.txt";
string strSourceBase = "C:\\Develop\\Apps\\StockPro\\";
string strSourcePath = strSourceBase + "Data\\";
string strResponse = "";
string strSourceFile = "";
// Transfer files
for (int intCtr = 0; intCtr <= 2; intCtr++)
Uri UriFileTarget = new Uri(strArrayTarget[intCtr]); //Uri("ftp://ftp.StockPickerMax.com/Data/AMEX.txt");
UploadRequest = (FtpWebRequest)WebRequest.Create(UriFileTarget);
UploadRequest.Credentials = new NetworkCredential("MyUserName", "MyPassword");
UploadRequest.UseBinary = true;
UploadRequest.Method = WebRequestMethods.Ftp.UploadFile;
// Copy the contents of the file to the request stream.
strSourceFile = strSourcePath + strArraySource[intCtr];
StreamReader SourceStream = new StreamReader(strSourceFile);
byte fileContents = Encoding.UTF8.GetBytes(SourceStream.ReadToEnd());
UploadRequest.ContentLength = fileContents.Length;
Stream RequestStream = UploadRequest.GetRequestStream();
RequestStream.Write(fileContents, 0, fileContents.Length);
FtpWebResponse UploadResponse = (FtpWebResponse)UploadRequest.GetResponse();
strResponse = UploadResponse.StatusDescription.ToString();
Open in new window
This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.