看了FileZilla源码,很是不明白,故向各位请教:下面是一个登陆服务器的客户端link的函数,我没看明白到底那里才是link的部分?
void CSiteManager::OnOK()
{
HTREEITEM item=m_cTree.GetSelectedItem();
t_SiteManagerItem *site=0;
if (item)
site=(t_SiteManagerItem *)m_cTree.GetItemData(item);
if (!site || site->NodeType != SITE)
return;
if (CheckValid())
{ //If an item is selected and the current selection is valid,
//we can save the data and close the dialog
//And don't forget to ask for the password first!
t_SiteManagerItem site2 = *(t_SiteManagerItem *)m_cTree.GetItemData(item);
BOOL bUseGSS=FALSE;
if (COptions::GetOptionVal(OPTION_USEGSS) && m_bPassDontSave)
{
USES_CONVERSION;
CString GssServers=COptions::GetOption(OPTION_GSSSERVERS);
LPCSTR lpszAsciiHost=T2CA(m_Host);
hostent *fullname=gethostbyname(lpszAsciiHost);
CString host;
if (fullname)
host=fullname->h_name;
else
host=m_Host;
host.MakeLower();
int i;
while ((i=GssServers.Find( _T(";") ))!=-1)
{
if (("."+GssServers.Left(i))==host.Right(GssServers.Left(i).GetLength()+1) || GssServers.Left(i)==host)
{
bUseGSS=TRUE;
break;
}
GssServers=GssServers.Mid(i+1);
}
}
if (!bUseGSS)
{
if (m_Logontype && (m_bPassDontSave || _ttoi(COptions::GetOption(OPTION_RUNINSECUREMODE))) )
{
CEnterSomething dlg(IDS_INPUTDIALOGTITLE_INPUTPASSWORD,IDS_INPUTDIALOGTEXT_INPUTPASSWORD,'*');
if (dlg.DoModal()!=IDOK)
return;
site2.Pass = dlg.m_String;
}
}
SaveData();
OnClose();
m_LastSite = site2;
m_nServerType=m_cServerType.GetCurSel();
CDialog::OnOK();
}
}就如FTP的link部分那样:
但是上面的SFTP我没看懂,向各位求救,谢谢.UINT CMyAppThread::FindServFileThread(LPVOID lParam)
{
CFtpParaClass::FILE_FTP_INFO* pInfo=new(CFtpParaClass::FILE_FTP_INFO);
FILETIME fileTime;
CString str,szFile,szFtpInfo;
WIN32_FIND_DATA findData;
HINTERNET hFind;
/*get hInetSession*/
HINTERNET hInetSession=InternetOpen(szAppName,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
/******************/
szFtpInfo="正在连接";
szFtpInfo+=szFtpName;
szFtpInfo+="服务器";
pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
/*ftp server connect*/
HINTERNET hFtpConn=InternetConnect(hInetSession,szFtpName,nPort,\
szFtpUser,szFtpPassword,INTERNET_SERVICE_FTP,INTERNET_FLAG_PASSIVE,0);
/********************/
if(!hFtpConn)
{
szFtpInfo=szFtpName;
szFtpInfo+="服务器未接上";
pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
InternetCloseHandle(hInetSession);
::Sleep(10);
return 0L;
}
szFtpInfo=szFtpName;
szFtpInfo+="服务器已连上,用户";
szFtpInfo+=szFtpUser;
szFtpInfo+="登录成功";
pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
DWORD dwLength=MAX_PATH;
void CSiteManager::OnOK()
{
HTREEITEM item=m_cTree.GetSelectedItem();
t_SiteManagerItem *site=0;
if (item)
site=(t_SiteManagerItem *)m_cTree.GetItemData(item);
if (!site || site->NodeType != SITE)
return;
if (CheckValid())
{ //If an item is selected and the current selection is valid,
//we can save the data and close the dialog
//And don't forget to ask for the password first!
t_SiteManagerItem site2 = *(t_SiteManagerItem *)m_cTree.GetItemData(item);
BOOL bUseGSS=FALSE;
if (COptions::GetOptionVal(OPTION_USEGSS) && m_bPassDontSave)
{
USES_CONVERSION;
CString GssServers=COptions::GetOption(OPTION_GSSSERVERS);
LPCSTR lpszAsciiHost=T2CA(m_Host);
hostent *fullname=gethostbyname(lpszAsciiHost);
CString host;
if (fullname)
host=fullname->h_name;
else
host=m_Host;
host.MakeLower();
int i;
while ((i=GssServers.Find( _T(";") ))!=-1)
{
if (("."+GssServers.Left(i))==host.Right(GssServers.Left(i).GetLength()+1) || GssServers.Left(i)==host)
{
bUseGSS=TRUE;
break;
}
GssServers=GssServers.Mid(i+1);
}
}
if (!bUseGSS)
{
if (m_Logontype && (m_bPassDontSave || _ttoi(COptions::GetOption(OPTION_RUNINSECUREMODE))) )
{
CEnterSomething dlg(IDS_INPUTDIALOGTITLE_INPUTPASSWORD,IDS_INPUTDIALOGTEXT_INPUTPASSWORD,'*');
if (dlg.DoModal()!=IDOK)
return;
site2.Pass = dlg.m_String;
}
}
SaveData();
OnClose();
m_LastSite = site2;
m_nServerType=m_cServerType.GetCurSel();
CDialog::OnOK();
}
}就如FTP的link部分那样:
但是上面的SFTP我没看懂,向各位求救,谢谢.UINT CMyAppThread::FindServFileThread(LPVOID lParam)
{
CFtpParaClass::FILE_FTP_INFO* pInfo=new(CFtpParaClass::FILE_FTP_INFO);
FILETIME fileTime;
CString str,szFile,szFtpInfo;
WIN32_FIND_DATA findData;
HINTERNET hFind;
/*get hInetSession*/
HINTERNET hInetSession=InternetOpen(szAppName,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
/******************/
szFtpInfo="正在连接";
szFtpInfo+=szFtpName;
szFtpInfo+="服务器";
pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
/*ftp server connect*/
HINTERNET hFtpConn=InternetConnect(hInetSession,szFtpName,nPort,\
szFtpUser,szFtpPassword,INTERNET_SERVICE_FTP,INTERNET_FLAG_PASSIVE,0);
/********************/
if(!hFtpConn)
{
szFtpInfo=szFtpName;
szFtpInfo+="服务器未接上";
pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
InternetCloseHandle(hInetSession);
::Sleep(10);
return 0L;
}
szFtpInfo=szFtpName;
szFtpInfo+="服务器已连上,用户";
szFtpInfo+=szFtpUser;
szFtpInfo+="登录成功";
pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
DWORD dwLength=MAX_PATH;
是设置链接参数的。
那哪一段才是连接SERVER的呢? 麻烦你多多指点.
哪里体现了SFTP的连接,我想用VC实现...
// If the file already exists, it is overwritten.
// (Specify "createNew" instead of "openOrCreate" to
// prevent overwriting existing files.)
const char * handle;
handle = sftp.openFile("hamlet.xml","writeOnly","openOrCreate"); //这个新文件建立在哪个目录下呢?
if (handle == 0 ) {
strOut.append(sftp.lastErrorText());
strOut.append("\r\n");
SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
return;
} // Upload from the local file to the SSH server.
success = sftp.UploadFile(handle,"c:/temp/hamlet.xml"); //或则上传的文件放在哪里呢?
if (success != true) {
strOut.append(sftp.lastErrorText());
strOut.append("\r\n");
SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
return;
}