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
Jose Saiz
1.5k
260
103.1k
FTP Upload Problem
Dec 19 2016 9:31 AM
FileInfo fileInfo =
new
FileInfo(filename);
string
sFtpHostSite =
"ftp://"
+ _sFtpHost.Replace(
"\0"
,
""
);
//- Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(sFtpHostSite + @
"/"
+ fileInfo.Name);
request.Method = WebRequestMethods.Ftp.UploadFile;
//- FTP site login credential.
request.Credentials =
new
NetworkCredential(_sFtpUserId.Trim().Replace(
"\0"
,
""
), _sFtpPwd.Trim().Replace(
"\0"
,
""
));
request.KeepAlive =
false
;
request.Method =
"STOR"
;
request.UseBinary =
true
;
// Copy the contents of the file to the request stream.
StreamReader sourceStream =
new
StreamReader(_sLocalPath.Replace(
"\0"
,
""
) + fileInfo.Name);
byte
[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
//- Wrapping up
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Console.WriteLine(
"Upload File Complete, status {0}"
, response.StatusDescription);
//- Good Bye
response.Close();
}
catch
(Exception oErMsg1)
{
Console.WriteLine(oErMsg1.Message,
"Error Occurred while uploading file to FTP server."
);
}
Does anyone knows why when the file gets uploaded to the FTP-Server it is not the same as the Local-directory?
Explain:
I compress zip some folders on the local computer using 7z library when I open the compressed zip file on my local for test it open and I can unzip it with no problem but once I upload it using my c# FTP-Upload the size of the file is different and when I download it regardless the FTP client used for download the file is corrupted I can't open it.
Please see my code for more detail
Thanks in advance
AL
Reply
Answers (
4
)
How to read pdf line by line and fetch the data in c#
My laptop get struck and i forcefully shutdown it and after