
Introduction
This tools allows you to edit files in Unix. vi is a good choice, but for Windows users, it is really a tough one. To simplify text editing, I have created a tool which actually downloads the file from a Unix server using FTP, and after editing it, uploads it back to the server.
Here are the files you need:
- NetDirectoryDlg.cpp
- FileEditor.cpp
It has only two dialogs:
- The NeDirectory dialog which captures the user ID, password, and server, and connects to the server and retrieves the file and directory information.
- Editor dialog which simply displays the file data.
This tool simply downloads the file from the server using FTP to a local machine. The local file is fed to the file editor. Once editing is done, it is uploaded back to the server using FTP.
I have used MFC's CFtpConnection
for this.
The code
Connecting to the FTP server
try
{
if(inetsess==NULL)
{
inetsess=new CInternetSession();
}
else
{
inetsess->Close();
inetsess=new CInternetSession();
}
ftp = inetsess->GetFtpConnection(m_server,m_user,m_pass);
}
catch(...)
{}
..
..
GetFiles();
}
}
Storing the records in the listbox
CFtpFileFind ftpFind(ftp);
BOOL bcontinue=TRUE;
CString str;
m_LstDir.ResetContent();
ftpFind.FindFile("");
while(bcontinue )
{
bcontinue = ftpFind.FindNextFile();
str = ftpFind.GetFileName();
if(str.GetLength()>0)
{
if(ftpFind.IsDirectory())
{
str.Insert(0,"./");
}
m_LstDir.AddString(str);
}
}
ftpFind.Close();
}
Double clicking the listbox and loading the file
CString str;
CString strCurDir;
CFile file;
m_LstDir.GetText(m_LstDir.GetCurSel(),str);
if(str.Left(2)!="./")
{
ftp->GetFile(str,str);
if(file.Open(str,CFile::modeRead))
{
file.Close();
CFileEditor edit(str);
if(edit.DoModal()==IDOK)
{
if(ftp->PutFile(str,str))
{
AfxMessageBox("Server File Updated...",MB_OK);
}
}
CFile::Remove(str);
}
}
else
{
if(ftp->GetCurrentDirectory(strCurDir))
{
strArrPath.Add(strCurDir);
}
if(ftp->SetCurrentDirectory(str))
{
GetFiles();
}
}
It can be customized with features like a treeview control or a full Explorer like view.