CFtpConnection::OpenFile()只能找开现有文件,CFtpConnection::PutFile()是把本地文件拷到FTP上,如果我想直接在FTP建立一个文件怎么办?
解决方案 »
- 为什么运行时总是出现“This application has requested the Runtime to terminate
- 请问应该如何自绘Edit控件?
- 文件指针关闭后,再调用file.close()是否可以?会不会产生错误或有什么隐患?
- 关于禁止修改网络属性的问题,搞不定了,求助
- 对话框程序,点按扭,用CreateProcess打开一个进程,但是我移动进程的窗口时,对话框对应的背景部分,内容会被檫掉!
- 如果查询数据库中CLOB字段中是否包含某关键字
- MFC数据存放问题
- 请问如何定义一个设备上下文?
- 问一个vc远程注入问题
- 急!vc++6.0如何开发windows2000服务程序
- 各位高手帮帮忙!!!!!!!!
- 请教查询问题!
CInternetFile *ff;
ff.Open((char*)FileName,CInternetFile::modeCreate¦CInternetFile::modeWrite)
用 CFtpConnection::SetCurrentDirectory 设置当前路径
然后 CFtpConnection::OpenFile(FILEPATHNAME,GENERIC_WRITE) 建立你想的文件,文件名可以是全路径,也可以只用文件名表示在当前目录下
接着用 刚才OpenFile 返回的 CInternetFile* 的 CInternetFile::Write(buf,count)方法写数据,
写完后CInternetFile::Close 即可
有些防火墙不允许外部ftp server流入数据,所以我用了Passive模式,即ftpconn=isession.GetFtpConnection("xxx.xxx.xxx.xxx","","",21,true);里的true
完整代码如下:#include <afxinet.h>
void CFtptestDlg::OnBtnftp()
{
// TODO: Add your control notification handler code here
CInternetSession isession;
CFtpConnection* ftpconn;
CInternetFile* ifile;
//建立ftp连接
ftpconn=isession.GetFtpConnection("xxx.xxx.xxx.xxx","","",21,true);
if(!ftpconn)
{
TRACE("GetFtpConnection FAILED!\n");
return;
}
//在当前目录(根目录)建立一个文件叫 ftptest.txt
ifile=ftpconn->OpenFile("ftptest.txt",GENERIC_WRITE);
if(!ifile)
{
TRACE("OpenFile FAILED!\n");
return;
}
//写数据
ifile->Write("test",4);
ifile->Close();
isession.Close();
}