Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
4
Answers
FTP Upload Problem
Ask a question
Ask a question
Upload Source Code:
Select only zip and rar file.
Jose Saiz
7y
286
1
Reply
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
Post
Reset
Cancel
Answers (
4
)
Next Recommended Forum
How to read pdf line by line and fetch the data in c#
My laptop get struck and i forcefully shutdown it and after