This is very specific. I need help with using a C# function in my my VB.Net program The function is in a DLL and the code is below:
public void UploadData(string FTPUri, string FilePath, string FileName,
string UserName, string Password)
{
StatusUp = new Int64[2];
reqFTP = (FtpWebRequest)FtpWebRequest.Create(FTPUri + FileName);
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(UserName, Password);
FileInfo fileInf = new FileInfo(FilePath);
FileStream fs = fileInf.OpenRead();
// modifyied code
int bytesSize = 0;
byte[] UpBuffer = new byte[2048];
ftpStream = reqFTP.GetRequestStream();
bytesSize = fs.Read(UpBuffer, 0, UpBuffer.Length);
while ((bytesSize = fs.Read(UpBuffer, 0, UpBuffer.Length)) > 0)
{
StatusUp[0] = StatusUp[0] + UpBuffer.Length;
StatusUp[1] = fileInf.Length;// +startPointInt;
ftpStream.Write(UpBuffer, 0, bytesSize);
}
fs.Close();
ftpStream.Close();
}
In my vb.net program I am calling it like this:
Dim FtpUpload As FTPUtility.ftpUtility = New FTPUtility.ftpUtility
FtpUpload.UploadData("ftp://ftp.xxx.xx", "C:\winzip.log", "/winzip.log", "uploader", "xxxx")
It works ok except it is 2 bytes short when it is done. I don't know enough C# to figure out if the C# code is wrong (I didn't write it and the guy who did has left the company), but somewhere it appears that it is not closing the file or something.
Any ideas?