In the recent project I build the transfer data feature in the airborne mission console software so that the aerial photo and video captured can be sent directly to ground system. For that purpose, I have built the ftp server in ground system, then I made the ftp sending data function included the uploading progress view.
In the making of FTP server I used the Filezilla server for Linux because the server is Linux Ubuntu based server. This is the open source ftp server management. It is very easy to be used. Also, provided the Microsoft installer version for Microsoft based ftp server. If you are interested, you can download the installer or the source code pack as at http://filezilla-project.org/.
Then I add user for ftp besides the administrator user. By this user I can send whatever data over internet from the outside of Ground system network (LAN). All of the data sent will be placed to the user folder in server directory.
In order to watch whether the server is working, I used the Filezilla Client. You can download the installer and code in the same site where Filezilla Server is existed. You just enter your username and password to access the server directly.
And then the last step I build the ftp feature in the main console software so that the mission console can be connected to ftp server on the ground. I built the function using C# code, below is the all code,
FileInfo fileInf = new FileInfo(fileToSend);
string uri = "ftpServerAddress.com" + fileInf.Name;
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftpServerAddress.com" + fileInf.Name));
reqFTP.Credentials = new NetworkCredential("userFTP", "passwordFTP");
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.UseBinary = true;
reqFTP.ContentLength = fileInf.Length;
int buffLength = 2048;
byte[] buff = new byte[buffLength];
int contentLen;
FileStream fs = fileInf.OpenRead();
try
{
Stream strm = reqFTP.GetRequestStream();
contentLen = fs.Read(buff, 0, buffLength);
residu = fileInf.Length;
while (contentLen != 0)
{
residu = residu - contentLen;
rest = fileInf.Length - residu;
SetLabel(labelProgress, ((rest / Convert.ToDouble(fileInf.Length) * 100).ToString("000.000")+" %"));
strm.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, bu_fLength);
}
strm.Close();
fs.Close();
if ((rest / Convert.ToDouble(fileInf.Length) * 100) >= 100)
{
buttonDataSend.IsEnabled = true;
}
}
catch
{
//MessageBox.Show(ex.Message, "Upload Error");
}
You get it???? It is very simple way to do the sending data over ftp protocol, but because it was developed by Microsoft, I believe that this function will be powerfull.
Tidak ada komentar:
Posting Komentar