Dovberman
asked on
how to copy a file from a local machine folder to an FTP folder
I need to copy a text file from a local folder to an ftp folder.
I believe that the steps are:
Read the local file contents into a filestream.
Initiate an FTPWebRequest.
Use a FTPWebRequest method to copy the filestream to the ftp folder.
Here are my source statements:
strSourcePath = "C:\\Develop\\Apps\\StockP ro\\Data\\ Changes\\" ;
string strSourceFileName = "Changes.txt";
string strSourceFile = strSourcePath + strSourceFileName;
// Create a filestream object
FileStream fs = new FileStream(strSourceFile, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader("Changes.txt" );
byte [] fileContents = Encoding.UTF8.GetBytes(sou rceStream. ReadToEnd( ));
// only one column is copied to the request stream.
//Use a FTPWebRequest method to copy the filestream to the ftp folder.
I believe that the steps are:
Read the local file contents into a filestream.
Initiate an FTPWebRequest.
Use a FTPWebRequest method to copy the filestream to the ftp folder.
Here are my source statements:
strSourcePath = "C:\\Develop\\Apps\\StockP
string strSourceFileName = "Changes.txt";
string strSourceFile = strSourcePath + strSourceFileName;
// Create a filestream object
FileStream fs = new FileStream(strSourceFile, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader("Changes.txt"
byte [] fileContents = Encoding.UTF8.GetBytes(sou
// only one column is copied to the request stream.
//Use a FTPWebRequest method to copy the filestream to the ftp folder.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I understand the principle, but have a few clarification questions:
// initialize parameters
string strSourcePath = "C:\\Develop\\Apps\\StockP ro\\Data\\ Changes\\" ;
string strSourceFile = strSourcePath + "Changes.txt";
string strSourceFileName = "Changes.txt";
//Structure of the Changes//Changes.txt file
//Date OldExchange OldSymbol NewExchange NewSymbol
//20131126 OTCBB BRVM OTCBB ZENO
//20131126 OTCBB CCRY OTCBB ARTR
//Create filestream
FileStream fs = new FileStream(strSourceFile, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
// ?? How do I create the filestream from the Changes.txt file?
// Copy the file to the ftp folder
Boolean blnResponse = CopyFTPFile(fs,strSourceFi leName,str SourcePath );
// initialize parameters
string strSourcePath = "C:\\Develop\\Apps\\StockP
string strSourceFile = strSourcePath + "Changes.txt";
string strSourceFileName = "Changes.txt";
//Structure of the Changes//Changes.txt file
//Date OldExchange OldSymbol NewExchange NewSymbol
//20131126 OTCBB BRVM OTCBB ZENO
//20131126 OTCBB CCRY OTCBB ARTR
//Create filestream
FileStream fs = new FileStream(strSourceFile, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
// ?? How do I create the filestream from the Changes.txt file?
// Copy the file to the ftp folder
Boolean blnResponse = CopyFTPFile(fs,strSourceFi
ASKER
I got it to work by making sure that the parameters were correctly structured.
Thanks,
Thanks,
ASKER
I got it to work by making sure that the parameters were correctly structured.
Thanks,
Thanks,
Happy that it worked for you!
Open in new window