TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
CherRon McLemore
NA
32
0
How do I connect to my server from my C# application?
Jun 28 2012 4:05 PM
I have some code and everything looks liek it should work fine but when I get to getrequeststream it throws the exception. help!!!!
public
void
uploadFile (
string
fileToUpload)
{
//create instance of login form to retrieve login data with created methods
loginForm
lf =
new
loginForm
();
//create FTP server login credentials
string
serverUser = lf.getLoginUser;
string
serverPass = lf.getLoginPass;
try {
FileInfo
toUpload =
new
FileInfo
(fileToUpload);
FtpWebRequest
request = (
FtpWebRequest
)
WebRequest
.Create(
"ftp://stepcommoditiesllc.com/"
+ toUpload.Name);
}
request.Method =
WebRequestMethods
.
Ftp
.UploadFile;
request.Credentials =
new
NetworkCredential
(serverUser, serverPass);
Stream
ftpStream = request.GetRequestStream(); //<-here I get the error
int
length = 1024;
byte
[] buffer =
new
byte
[length];
int
bytesRead = 0;
FileStream
file =
File
.OpenRead(fileToUpload);
do
{
bytesRead = file.Read(buffer, 0, length);
ftpStream.Write(buffer, 0, bytesRead);
} while (bytesRead != 0);
file.Close();
ftpStream.Close();
catch
{
//Did not connect to server
MessageBox
.Show(
"Error - Did Not Connect"
);
}
Reply
Answers (
0
)
why c# !!!!!
when button clicked